Posts

Showing posts from December, 2019

MongoDB indexing

Image
What is MongoDB Index? For any kind of database, indexes are of great importance. In MongoDB, Indexes helps to solve queries more efficiently. Indexes are a special data structure used to locate the record in the given table very quickly without being required to traverse through every record in the table. MongoDB uses these indexes to limit the number of documents that had to be searched in a collection. The data structure that is used by an index is a Binary Tree. a.  Default Index In MongoDB indexing, all the collections have a default index on the _id field. If we don’t specify any value for the _id the MongoDB will create _id field with an object value. This index prevents clients from creating two documents with the same value _id field. b.  Create an Index In MongoDB, a user can create indexes using the following  syntax. Db.collection_name. createIndex ( <key and index type specification>, <options> ) This method creates an index ...