By
default mongoDB build Indexes in foreground, it prevents all the read write
operations to the database. When building an index on a collection, the
database that holds the collection is unavailable for read or write operations
until the index build completes.
Background
index construction allows read and write operations to continue while building
the index. Creation of background index takes more than foreground index.
How to perform
indexing at background
While
creating index, set the option “background” to true.
Example
> db.employee.ensureIndex({"firstName" : 1}, {"background":true}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 2, "numIndexesAfter" : 3, "ok" : 1 }
Note:
1.
mongo shell session or connection where you are creating the index will block
until the index build is complete. To continue issuing commands to the
database, open another connection or mongo instance.
2.
If MongoDB is building an index in the background, you cannot perform other
administrative operations involving that collection.
No comments:
Post a Comment