This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Index Properties”.
1. ________ indexes expire documents after the specified number of seconds has passed since the indexed field value.
a) Hashed
b) Unique
c) Multikey
d) TTL
View Answer
Explanation: The expiration threshold is the indexed field value plus the specified number of seconds.
2. Point out the correct statement.
a) If you build a TTL index in the foreground, MongoDB does not remove expired documents as soon as the index finishes building
b) The TTL index does guarantee that expired data will be deleted immediately upon expiration
c) Duration of the removal operation depends on the workload of your mongod instance
d) None of the mentioned
View Answer
Explanation: There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.
3. When the TTL thread is active, you will see _______ operations in the output of db.currentOp().
a) delete
b) update
c) insert
d) none of the mentioned
View Answer
Explanation: A background thread in mongod reads the values in the index and removes expired documents from the collection.
4. The background task that removes expired documents runs every ________ seconds.
a) 15
b) 45
c) 60
d) 120
View Answer
Explanation: As a result, documents may remain in a collection during the period between the expiration of the document and the running of the background task.
5. Point out the wrong statement.
a) The unique constraint applies to separate documents in the collection
b) Unique index prevents separate documents from having the same value for the indexed key
c) Index does prevent a document from having multiple elements or embedded documents in an indexed array from having the same value
d) None of the mentioned
View Answer
Explanation: In the case of a single document with repeating values, the repeated value is inserted into the index only once.
6. On replica sets, the TTL background thread only deletes documents on _____________
a) primary
b) secondary
c) upadte
d) none of the mentioned
View Answer
Explanation: Secondary members replicate deletion operations from the primary.
7. You can combine the ________ constraint with the sparse index to filter these null values from the unique index and avoid the error.
a) Hashed
b) Unique
c) Sparse
d) Compound
View Answer
Explanation: If a document does not have a value for the indexed field in a unique index, the index will store a null value for this document.
8. You may not specify a unique constraint on a ______ index.
a) Hashed
b) Unique
c) Sparse
d) Compound
View Answer
Explanation: Because of the unique constraint, MongoDB will only permit one document that lacks the indexed field.
9. Which of the following indexes are always sparse?
a) 2dsphere
b) 2d
c) geoHaystack
d) all of the mentioned
View Answer
Explanation: 2dsphere (version 2), 2d, geoHaystack, and text indexes are always sparse.
Sanfoundry Global Education & Learning Series – MongoDB.
Here’s the list of Best Books in MongoDB.
- Check MongoDB Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs