C100DBA practice question 23 of 25
Which command can be used to rebuild the indexes on a collection in MongoDB?
Full set: 130 questionsThe db.collection.reIndex() command is the designated method for rebuilding all indexes on a collection. This operation drops all existing user-created indexes and then recreates them from scratch. The id index is not affected. This command is useful for reclaiming disk space or improving performance after index fragmentation or significant data churn. The command takes no arguments.
A. This syntax attempts to create a new index on a field named relndex. It does not rebuild existing indexes.
B. The reIndex() command does not accept any arguments. Passing an index key specification like {author:1} results in an error.
D. This is invalid syntax. createIndex() does not return an object on which reIndex() can be chained.
1. MongoDB Manual, db.collection.reIndex(), Version 7.0. "The db.collection.reIndex() method drops all indexes on a collection and recreates them. This operation may be expensive for collections that have a large amount of data and/or a large number of indexes."
2. MongoDB Manual, reIndex command, Version 7.0. "The reIndex command drops all indexes on a collection and rebuilds them. Syntax: { reIndex: }."
Keep practicing
Take the free C100DBA practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other C100DBA practice questions
- Question 1If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which…
- Question 2The oplog (operations log) is a special capped collection that keeps a rolling record of …
- Question 3‘$set' sets the value of
- Question 4What does the totalKeysExamined field returned by the explain method indicate?
- Question 5Which mongodb tools allow us to work with our data in a human readable format?
- Question 6Which of the following is incorrect statement about find and findOne operations in MongoD…
