Challenge - 5 Problems
Capped Collection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of inserting documents into a capped collection
Given a capped collection with a max size of 1000 bytes and max 3 documents, what will be the count of documents after inserting 4 documents?
MongoDB
db.createCollection('logs', { capped: true, size: 1000, max: 3 }); db.logs.insertMany([ { event: 'start' }, { event: 'process' }, { event: 'end' }, { event: 'cleanup' } ]); db.logs.countDocuments();
Attempts:
2 left
💡 Hint
Remember capped collections keep only the most recent documents up to the max limit.
✗ Incorrect
Capped collections automatically remove oldest documents when the max document count or size is exceeded. Here, max is 3, so after inserting 4 documents, only the latest 3 remain.
🧠 Conceptual
intermediate2:00remaining
Behavior of capped collections on document update
What happens when you update a document in a capped collection that increases its size beyond the allocated space?
Attempts:
2 left
💡 Hint
Think about the fixed-size nature of capped collections.
✗ Incorrect
In capped collections, documents cannot grow in size after insertion. Updates that increase document size will fail with an error.
📝 Syntax
advanced2:00remaining
Correct syntax to create a capped collection with size and max documents
Which of the following commands correctly creates a capped collection named 'events' with a max size of 5000 bytes and max 100 documents?
Attempts:
2 left
💡 Hint
Check the exact option names and data types for capped collection options.
✗ Incorrect
The correct options are 'size' for bytes and 'max' for max documents. They must be numbers, not strings. There is no method setMaxDocuments.
❓ optimization
advanced2:00remaining
Optimizing capped collection size for high insert rate
You have a capped collection with size 1MB and max 1000 documents. Your application inserts 2000 documents per minute. What is the best way to avoid losing important recent data?
Attempts:
2 left
💡 Hint
Think about how capped collections manage storage and document retention.
✗ Incorrect
Increasing size and max documents allows the capped collection to hold more data before removing old documents, preserving recent data better.
🔧 Debug
expert2:00remaining
Identifying error when inserting large document into capped collection
You created a capped collection with size 1024 bytes. When inserting a document of 1500 bytes, what error will MongoDB raise?
Attempts:
2 left
💡 Hint
Consider how capped collections handle documents larger than their size limit.
✗ Incorrect
MongoDB raises a WriteError indicating the document size exceeds the capped collection size because capped collections cannot store documents larger than their allocated size.