0
0
MongoDBquery~20 mins

Capped collections for fixed-size data in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Capped Collection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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();
A4
B3
C2
D1
Attempts:
2 left
💡 Hint
Remember capped collections keep only the most recent documents up to the max limit.
🧠 Conceptual
intermediate
2: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?
AThe update fails with an error because documents cannot grow in capped collections.
BThe document is moved to a new location to accommodate the size increase.
CThe document is truncated to fit the original size limit.
DThe collection automatically increases its size to fit the updated document.
Attempts:
2 left
💡 Hint
Think about the fixed-size nature of capped collections.
📝 Syntax
advanced
2: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?
Adb.createCollection('events', { capped: true, size: 5000, max: 100 });
Bdb.createCollection('events', { capped: true, maxSize: 5000, maxDocs: 100 });
Cdb.createCollection('events', { capped: true, size: 5000 }); db.events.setMaxDocuments(100);
Ddb.createCollection('events', { capped: true, size: '5000', max: '100' });
Attempts:
2 left
💡 Hint
Check the exact option names and data types for capped collection options.
optimization
advanced
2: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?
ADisable capping and use a normal collection with TTL indexes.
BDecrease the capped collection size to force faster removal of old data.
CIncrease the capped collection size and max document count to hold more data.
DInsert documents in batches of 1000 to reduce overhead.
Attempts:
2 left
💡 Hint
Think about how capped collections manage storage and document retention.
🔧 Debug
expert
2: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?
ANo error, document is truncated automatically
BCappedPositionLost: document cannot fit in capped collection
CBSONObjectTooLarge: document exceeds maximum size
DWriteError: document size exceeds capped collection size
Attempts:
2 left
💡 Hint
Consider how capped collections handle documents larger than their size limit.