

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Build index in the background with MongoDB
To create index in the background, use createIndex() method and set “background: true” as in the below syntax −
db.yourCollectionName.createIndex({"yourFieldName1":1,"yourFieldName2":1},{background: true} );
Let us implement the above syntax in order to create index and set background −
> db.indexCreationDemo.createIndex({"StudentName":1,"StudentAge":1},{background: true} ); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
Let us display the indexes −
> db.indexCreationDemo.getIndexes();
This will produce the following output −
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "web.indexCreationDemo" }, { "v" : 2, "key" : { "StudentName" : 1, "StudentAge" : 1 }, "name" : "StudentName_1_StudentAge_1", "ns" : "web.indexCreationDemo", "background" : true } ]
- Related Questions & Answers
- Build (escape) regexp in MongoDB?
- How to dynamically build MongoDB query?
- How to create an index with MongoDB?
- Prevent duplicates of multiple fields with index in MongoDB
- Set unique index in MongoDB
- How to improve MongoDB queries with multikey index in array?
- Set MongoDB compound index with a fixed value field
- Repeat the background image with CSS
- Set the Background Attachment with CSS
- Specify the background image with CSS
- Create index in a MongoDB collection?
- How does MongoDB index arrays?
- Set the Background Image Position with CSS
- Add transparency to the background with CSS
- Animated background with CSS
Advertisements