Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumMongoDBbucket and outlier patternsSingle-choice MCQ

A bucket document accumulates measurements with `$push` and is capped at 200 entries per bucket using a guarded upsert. Which `update`/`findOneAndUpdate` filter+update correctly appends to an existing not-yet-full bucket OR creates a new bucket when none has room, in a single atomic operation?

db.buckets.findOneAndUpdate( { device: "d1", count: { $lt: 200 } }, { $push: { measurements: m }, $inc: { count: 1 }, $setOnInsert: { device: "d1", bucketStartedAt: now } }, { upsert: true, returnDocument: "after" } )