MongoDB Questions and Answers – Index Management

«
»

This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Index Management”.

1. To modify an existing index, you cannot just re-issue the _________ method with the updated specification of the index.
a) dropIndex()
b) modIndex()
c) createIndex()
d) none of the mentioned
View Answer

Answer: c
Explanation: To modify the index, you must drop the index first.

2. Point out the wrong statement.
a) To modify an existing index, you need to drop and recreate the index
b) Your client library may have a different or additional interface for this operation
c) To see the status of an indexing process, you can use the db.statusOp() method in the mongo shell
d) None of the mentioned
View Answer

Answer: c
Explanation: To see the status of an indexing process, you can use the db.currentOp() method in the mongo shell.

advertisement

3. If you need to rebuild indexes for a collection you can use the _________ method to rebuild all indexes on a collection in a single operation.
a) db.collection.Index()
b) db.collection.reIndex()
c) db.collection.rebuildIndex()
d) none of the mentioned
View Answer

Answer: a
Explanation: This operation drops all indexes, including the _id index, and then rebuilds all indexes.

4. To terminate an ongoing index build, use the __________ method in the mongo shell.
a) db.currentOp()
b) db.killOp()
c) db.removeOp()
d) all of the mentioned
View Answer

Answer: b
Explanation: For index builds, the effects of db.killOp() may not be immediate and may occur well after much of the index build operation has completed.

advertisement
advertisement

5. Point out the correct statement.
a) After 4.0, you cannot terminate both background index builds and foreground index builds
b) Before MongoDB 2.1, you could only terminate background index builds
c) After 2.4, you can terminate both background index builds and foreground index builds
d) None of the mentioned
View Answer

Answer: c
Explanation: You cannot terminate a replicated index build on secondary members of a replica set.

6. In the mongo shell, you can use the ______ method to return a list of the indexes on a collection.
a) getallIndexes()
b) getretIndexes()
c) getIndexes()
d) none of the mentioned
View Answer

Answer: c
Explanation: When performing maintenance you may want to check which indexes exist on a collection.

advertisement

7. __________ views partial execution statistics collected during plan selection.
a) curs.explain()
b) cursor.explain()
c) cursr.explain()
d) all of the mentioned
View Answer

Answer: b
Explanation: Run db.collection.explain() or the cursor.explain() method in allPlansExecution mode.

8. The __________ operator constrains the results of a geospatial $near or $nearSphere query to the specified distance.
a) $center
b) $maxDistance
c) $minDistance
d) all of the mentioned
View Answer

Answer: b
Explanation: The measuring units for the maximum distance are determined by the coordinate system in use.

advertisement

9. To force MongoDB to use a particular index for a db.collection.________ operation, specify the index with the hint() method.
a) query()
b) find()
c) index()
d) all of the mentioned
View Answer

Answer: b
Explanation: Append the hint() method to the find() method.

10. Specify the ______ operator to the hint() method to prevent MongoDB from using any index.
a) $unique
b) $natural
c) $spatial
d) all of the mentioned
View Answer

Answer: b
Explanation: To view the execution statistics for a specific index, append to the db.collection.find() the hint() method followed by cursor.explain().

advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Reference Books in MongoDB.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!
advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter