Indexes are a critical aspect of MongoDB for optimizing query performance and ensuring efficient data retrieval. By reducing the amount of data scanned during queries, indexes can significantly improve application speed. These MCQs help candidates grasp the key concepts and practical applications of indexing, preparing them for interview questions on database optimization and design.
1.) What is the purpose of an index in MongoDB?
A) To reduce storage size
B) To improve query performance
C) To enforce schema validation
D) To create relationships between documents
2.) What type of index is automatically created for every MongoDB collection?
A) Text Index
B) Geospatial Index
C) Single Field Index on _id
D) Compound Index
3.) How do you create a single field index in MongoDB?
A) db.collection.addIndex({ field: 1 })
B) db.collection.createIndex({ field: 1 })
C) db.collection.index({ field: 1 })
D) db.collection.addSingleIndex({ field: 1 })
4.) What does { field: -1 } specify when creating an index?
A) No index
B) Descending index
C) Text index
D) Geospatial index
5.) What is a compound index?
A) An index that combines multiple fields
B) An index created on a single field
C) A special type of text index
D) A geospatial index
6.) Which method removes an index from a collection?
A) db.collection.removeIndex({ field: 1 })
B) db.collection.deleteIndex({ field: 1 })
C) db.collection.dropIndex({ field: 1 })
D) db.collection.clearIndex({ field: 1 })
7.) Which type of index is used to support text search in MongoDB?
A) Geospatial Index
B) Compound Index
C) Text Index
D) Full-text Index
8.) What is the command to create a text index in MongoDB?
A) db.collection.createTextIndex({ field: 1 })
B) db.collection.createIndex({ field: “text” })
C) db.collection.addTextIndex({ field: 1 })
D) db.collection.indexText({ field: 1 })
9.) What does the db.collection.getIndexes() command do?
A) Displays the query plan
B) Deletes all indexes
C) Lists all indexes on the collection
D) Creates a default index
10.) Which of the following is true about a compound index?
A) The order of fields in a compound index does not matter.
B) The order of fields in a compound index matters.
C) Compound indexes are automatically created on all fields.
D) Compound indexes cannot include more than two fields.
Related