Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Covers MongoDB schema design patterns and anti-patterns, including embed-vs-reference decisions, unbounded arrays, and schema validation.
70% 87%+17 ptsof test cases passed
Passed 20 of 23 test cases with the skill, and 16 of 23 without it.
3 of 3 safety checks passed
16 agent runs
Group a series of related items into bounded arrays within a single document. The bucket pattern separates long series of data into distinct objects, reducing document count and aligning storage with how data is actually consumed. This is especially useful when an application accesses data in fixed-size groups (e.g. pages).
For time-series data, prefer Time Series Collections, which apply bucketing automatically with built-in compression and indexing optimizations.
Incorrect (one document per event):
Storing one document per stock trade (e.g. { ticker, customerId, type, quantity, date }) means the application pages through trades using skip/limit, which degrades as offset grows. Each trade is a separate document and index entry.
Correct (bucket pattern - group by customer, bounded per page):
Each document holds up to N trades for one customer (e.g. 10 trades = one page). The _id encodes customer ID and the first trade’s epoch seconds (e.g. "123_1698349623"), with a count field and a history array of trade objects. One bucket equals one page of data — a regex on _id uses the default _id index with no extra index needed, and document count drops by up to the bucket-size factor.
Insert with atomic upsert:
// Insert a new trade into the correct bucket
db.trades.findOneAndUpdate(
{
"_id": /^123_/, // Match buckets for this customer
"count": { $lt: 10 } // Only if bucket isn't full
},
{
$push: {
history: {
type: "buy",
ticker: "MSFT",
qty: 42,
date: ISODate("2023-11-02T11:43:10Z")
}
},
$inc: { count: 1 },
Published skills whose descriptions closely match this one, with their benchmark result.
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.