0
0
MongoDBquery~20 mins

Document size and growth patterns in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Document Size Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Calculate average document size in a collection
Given a MongoDB collection named orders, which aggregation pipeline will correctly calculate the average size in bytes of documents stored in this collection?
A[{ $group: { _id: null, avgSize: { $avg: { $bsonSize: "$ROOT" } } } }]
B[{ $project: { size: { $strLenCP: "$ROOT" } } }, { $group: { _id: null, avgSize: { $avg: "$size" } } }]
C[{ $project: { size: { $bsonSize: "$ROOT" } } }, { $group: { _id: null, avgSize: { $avg: "$size" } } }]
D[{ $count: "totalDocs" }, { $group: { _id: null, avgSize: { $avg: "$totalDocs" } } }]
Attempts:
2 left
💡 Hint
Use $bsonSize to get the size of each document in bytes before averaging.
🧠 Conceptual
intermediate
1:30remaining
Understanding document growth and padding
In MongoDB, when a document grows in size due to updates, what mechanism helps reduce the need for document moves and fragmentation?
APre-allocating padding space around documents to accommodate growth
BAutomatically compressing documents on disk
CStoring documents in fixed-size blocks without padding
DUsing indexes to store document size metadata
Attempts:
2 left
💡 Hint
Think about how MongoDB avoids moving documents when they grow slightly.
📝 Syntax
advanced
2:00remaining
Identify the correct syntax to find documents larger than 16MB
Which MongoDB query correctly finds documents in the files collection whose BSON size exceeds 16 megabytes (16 * 1024 * 1024 bytes)?
Adb.files.find({ size: { $gt: 16777216 } })
Bdb.files.find({ $expr: { $gt: [ { $bsonSize: "$ROOT" }, 16777216 ] } })
Cdb.files.find({ $bsonSize: { $gt: 16777216 } })
Ddb.files.aggregate([{ $match: { $bsonSize: { $gt: 16777216 } } }])
Attempts:
2 left
💡 Hint
Use $expr to compare computed values in queries.
🔧 Debug
advanced
1:30remaining
Why does this update cause document move despite padding?
A document in MongoDB has padding to allow growth. However, after an update that adds a large array, the document moves to a new location. What is the most likely reason?
AThe document was indexed and indexes prevent moves
BThe update used $set instead of $push
CMongoDB does not support document moves after creation
DThe update increased the document size beyond the allocated padding space
Attempts:
2 left
💡 Hint
Consider the size limits of padding space.
optimization
expert
2:30remaining
Optimizing document growth to reduce fragmentation
You have a collection where documents frequently grow due to added fields and arrays. Which approach best reduces document moves and fragmentation over time?
ADesign documents with reserved fields or arrays pre-allocated with empty values
BUse smaller documents and split data into multiple collections
CDisable padding factor to save disk space
DUse capped collections to limit document size
Attempts:
2 left
💡 Hint
Think about how to prepare documents for growth in advance.