- MongoDB is one of the leading NoSQL database. It is written in C++ Program.
- It provides high performance and availability and high scalable.
- Indexing in MongoDB is used to make query processing more efficient.
- The MongoDB scan every document in the collection and retrieve only those documents that match the query, where there is no indexing.
- Indexes are special data structures that stores some information related to the documents such that it becomes easy for MongoDB to find the right data file.
- Indexes are ordered by the value of the field specified in the index.
Index Creating :
- createIndex() is a method that allows user to create an index.
Syntax :
For Example,
- In createIndex() method, there are five types of parameters:
-
- background (Boolean)
- unique (Boolean)
- name (string)
- sparse (Boolean)
Index for Drop :
- dropIndex() is a method that allows users to drop an index.
- This method can delete only one index at a time.
- MongoDB provides the dropIndexes() method that takes multiple indexes as its parameters.
Syntax :
Get description of all indexes :
- It will retrieve all the description of the indexes created within the collection.