This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Data from Collections”.
1. Which of the following collection do not support the TTL property?
a) Compound indexes
b) Primary indexes
c) Composite indexes
d) All of the mentioned
View Answer
Explanation: The TTL index is a single field index.
2. Point out the correct statement.
a) Data expiration is useful for some classes of information, including machine generated event data, logs, and session information
b) A special TTL index property supports the implementation of TTL collections
c) TTL collections make it possible to store data in MongoDB and have the mongod automatically remove data after a specified number of seconds or at a specific clock time
d) All of the mentioned
View Answer
Explanation: The TTL feature relies on a background thread in mongod that reads the date-typed values in the index and removes expired documents from the collection.
3. If the indexed field in a document is not a _____ or an array that holds a date value(s), the document will not expire.
a) DATE
b) TIME
c) DATETIME
d) All of the mentioned
View Answer
Explanation: Built-in first-in-first-out property maintains the order of events while managing storage use.
4. Point out the correct statement.
a) TTL indexes expire documents after the specified number of seconds has passed since the indexed field value
b) TTL indexes are special compound indexes
c) If a document does not contain the indexed field, the document will expire
d) None of the mentioned
View Answer
Explanation: The expiration threshold is the indexed field value plus the specified number of seconds.
5. Secondary members replicate _________ operations from the primary.
a) Update
b) Drop
c) Insert
d) None of the mentioned
View Answer
Explanation: On replica sets, the TTL background thread only deletes documents on the primary.
6. A collection with a TTL index has __________ enabled.
a) usePowerOf3Sizes
b) usePowerOf2Sizes
c) usePowerOf4Sizes
d) none of the mentioned
View Answer
Explanation: As a result of enabling usePowerOf2Sizes, MongoDB must allocate more disk space relative to data size.
7. Which field does not support TTL indexes?
a) _identity
b) _option
c) _id
d) None of the mentioned
View Answer
Explanation: You cannot create a TTL index on a capped collection because MongoDB cannot remove documents from a capped collection.
8. You cannot use _________ to change the value of expireAfterSeconds of an existing index.
a) createIndex()
b) dropIndex()
c) removeIndex()
d) none of the mentioned
View Answer
Explanation: Instead use the collMod database command in conjunction with the index collection flag. Otherwise, to change the value of the option of an existing index, you must drop the index first and recreate.
9. You cannot create a TTL index on a ________ collection.
a) Sharded
b) Capped
c) Primary
d) None of the mentioned
View Answer
Explanation: MongoDB cannot remove documents from a capped collection.
Sanfoundry Global Education & Learning Series – MongoDB.
Here’s the list of Best Books in MongoDB.
- Practice Programming MCQs
- Apply for Programming Internship
- Check Information Technology Books
- Check MongoDB Books