Wednesday, 6 January 2016

MongoDB -- Indexes

searching the data based on some query becomes very pathetic. so we use indexes. index is just same as indexes that are seen in the textbooks. through the indexes we go directly to the pages rather than searching the entire book. in books the indexes holds page numbers of  contents of book. in a same manner, indexes here holds some specific value so that traversing to the specific data field is possible.

 creating an index

command:
  db.collectionname.ensureIndex({"key1":1}) --- ascending order index
  db.collectionname.ensureIndex({"key1":-1}) --- descending order index

or 
  db.collectionname.ensureIndex({"key1":1,"key2":-1})

No comments:

Post a Comment