MongoDB Questions and Answers – Capped Collections

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

Answer: a
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

Answer: a
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

Answer: a
Explanation: Built-in first-in-first-out property maintains the order of events while managing storage use.

advertisement
advertisement

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

Answer: a
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

Answer: a
Explanation: Capped collections guarantee preservation of the insertion order.

Note: Join free Sanfoundry classes at Telegram or Youtube

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

Answer: a
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

Answer: b
Explanation: Use the isCapped() method to determine if a collection is capped, as: db.collection.isCapped().

advertisement

8. ___________ convert a non-capped collection to a capped collection.
a) ToCapped
b) convertToCap
c) convertToCapped
d) none of the mentioned
View Answer

Answer: c
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

Answer: c
Explanation: MongoDB does not support the convertToCapped command in a sharded cluster.

advertisement

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

Answer: b
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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.