- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Building Multiple Indexes at once in MongoDB?
In order to build multiple indexes at once, you need to use createIndexes() and pass multiple keys into an array. Following is the query for building multiple indexes at once.
>db.multipleIndexesDemo.createIndexes([{"First":1},{"Second":1},{"Third":1},{"Fourth":1},{"Fifth":1}]);
This will produce the following output
{ "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 6, "ok" : 1 }
Now get all the indexes
> db.multipleIndexesDemo.getIndexes();
This will produce the following output
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.multipleIndexesDemo" }, { "v" : 2, "key" : { "First" : 1 }, "name" : "First_1", "ns" : "test.multipleIndexesDemo" }, { "v" : 2, "key" : { "Second" : 1 }, "name" : "Second_1", "ns" : "test.multipleIndexesDemo" }, { "v" : 2, "key" : { "Third" : 1 }, "name" : "Third_1", "ns" : "test.multipleIndexesDemo" }, { "v" : 2, "key" : { "Fourth" : 1 }, "name" : "Fourth_1", "ns" : "test.multipleIndexesDemo" }, { "v" : 2, "key" : { "Fifth" : 1 }, "name" : "Fifth_1", "ns" : "test.multipleIndexesDemo" } ]
Advertisements