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
Frequent $lookup operations on hot paths can indicate over-normalization. $lookup is useful, but repeated joins can be slower and more resource-intensive than querying a single collection, especially when supporting indexes or match selectivity are weak. If the same related fields are read together often, consider embedding or extended references.
Incorrect (constant $lookup for common operations):
// Every product page requires repeated joins across collections
db.products.aggregate([
{ $match: { _id: productId } },
{ $lookup: {
from: "categories", // Collection scan #2
localField: "categoryId",
foreignField: "_id",
as: "category"
}},
{ $lookup: {
from: "brands", // Collection scan #3
localField: "brandId",
foreignField: "_id",
as: "brand"
}},
{ $unwind: "$category" },
{ $unwind: "$brand" }
])
// Multiple join stages add planning/execution overhead on hot paths
Join cost depends on cardinality, stage order, index support, and result size. Measure before deciding to embed.
Correct (denormalize frequently-joined data):
Embed data that is always displayed alongside the product directly in the product document: include category fields (_id, name, path) and brand fields (_id, name, logo) as subdocuments. A single indexed query returns complete product data without $lookup. Listing queries (e.g. by category) also run against a single collection.
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.