Example 1 — Sample Data
Six products with category, price, and sold count—enough for ranking and facet counts.
db.products.drop()
db.products.insertMany([
{ title: "Wireless Mouse", category: "Electronics", price: 25, sold: 120 },
{ title: "Mechanical Keyboard", category: "Electronics", price: 89, sold: 85 },
{ title: "Desk Lamp", category: "Home", price: 35, sold: 60 },
{ title: "Monitor 27in", category: "Electronics", price: 220, sold: 45 },
{ title: "Notebook Set", category: "Stationery", price: 12, sold: 200 },
{ title: "Webcam HD", category: "Electronics", price: 55, sold: 95 }
]) How the Data Is Stored in MongoDB
After the insert, MongoDB keeps six documents in products. Run find() to see them:
db.products.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
category | "Electronics" | Group key for facet counts |
sold | 200 | Units sold (ranking) |
price | 25 | Used when sorting a page of rows |
How It Works
- Reset once.
drop()keeps demos repeatable. - Insert six products. Mixed categories feed the facet counts.
- Ready for branches. Next examples fan this set into multiple summaries.

