This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Capped Collections”.
1. Which of the following collections work in a way similar to circular buffers?
a) Capped
b) Secondary
c) Sharded
d) All of the mentioned
View Answer
Explanation: Once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
2. Point out the correct statement.
a) Capped collections automatically remove the oldest documents in the collection without requiring scripts or explicit remove operations
b) Capped collections do not guarantee that insertion order is identical to the order on disk
c) Capped collections does not allow updates that fit the original document size
d) All of the mentioned
View Answer
Explanation: Document does not change its location on disk.
3. _________ stores a log of the operations in a replica set.
a) oplog.rs
b) log.rs
c) oplog
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. ___________ is also used to pre-allocate space for an ordinary collection.
a) db.createCollection.
b) db.create
c) db.createColl
d) all of the mentioned
View Answer
Explanation: MongoDB creates a collection implicitly when the collection is first referenced in a command.
5. Point out the wrong statement.
a) Queries need an index to return documents in insertion order
b) The options document creates a capped collection or preallocates space in a new ordinary collection
c) Capped collections have maximum size or document counts that prevent them from growing beyond maximum thresholds
d) None of the mentioned
View Answer
Explanation: Capped collections guarantee preservation of the insertion order.
6. If you perform a ________ on a capped collection with no ordering specified, MongoDB guarantees that the ordering of results is the same as the insertion order.
a) find()
b) write()
c) modify()
d) none of the mentioned
View Answer
Explanation: To retrieve documents in reverse insertion order, issue find() along with the sort() method with the $natural parameter set to -1.
7. Which of the following should is used to check whether collection is capped or not?
a) isCAP()
b) isCapped()
c) isColl()
d) none of the mentioned
View Answer
Explanation: Use the isCapped() method to determine if a collection is capped, as: db.collection.isCapped().
8. ___________ convert a non-capped collection to a capped collection.
a) ToCapped
b) convertToCap
c) convertToCapped
d) none of the mentioned
View Answer
Explanation: convertToCapped takes an existing collection (<collection>) and transforms it into a capped collection with a maximum size in bytes, specified by the size argument (<capped size>).
9. _________ command creates the capped collection and imports the data.
a) CollectionAsCapped
b) cloneCollection
c) cloneCollectionAsCapped
d) None of the mentioned
View Answer
Explanation: MongoDB does not support the convertToCapped command in a sharded cluster.
10. Which of the following command obtains a global write lock and will block other operations until it has completed?
a) ToCapped
b) isCapped
c) convertToCapped
d) None of the mentioned
View Answer
Explanation: If the capped size specified for the capped collection is smaller than the size of the original uncapped collection, then MongoDB will overwrite documents in the capped collection based on the insertion order, or first in, first out order.
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