Common Mistakes
Unbounded Arrays and Huge Documents
The 16MB ceiling, arrays that never stop growing, and the split you should have made earlier.
Problem. $push onto users.events or users.orderIds forever. The document hits 16MB, every profile read is huge, the multikey index explodes.
db.users.updateOne(
{ name: "Rahul" },
{ $push: { events: { type: "click", at: new Date() } } }
)db.events.insertOne({
userId: ObjectId("64a1b2c3d4e5f6a7b8c90001"),
type: "click",
at: new Date()
})
// optional cache on the user
{ name: "Rahul", recentOrderIds: [ /* last 10, capped */ ] }skills of length 2 and items of length 3 are not this bug. orderIds that grow with every checkout are. Projection $slice does not stop the write from growing the document. Bucket pattern if you are storing time series — still not an infinite array on Rahul.
Interview question
Why is an unbounded array inside a document a problem?
Documents cap at 16MB, so the write eventually fails. Before that, every read fetches the whole array and every push rewrites the document. Multikey indexes get one key per element. Put unbounded data in its own collection with parentId.