Example 1 — Sample Data
Seven orders across categories and countries—enough for category totals and a grand total.
db.orders.drop()
db.orders.insertMany([
{ product: "Laptop", category: "Electronics", country: "US", amount: 1200, status: "completed" },
{ product: "Mouse", category: "Electronics", country: "US", amount: 25, status: "completed" },
{ product: "Desk", category: "Furniture", country: "US", amount: 450, status: "completed" },
{ product: "Chair", category: "Furniture", country: "UK", amount: 180, status: "completed" },
{ product: "Monitor", category: "Electronics", country: "UK", amount: 320, status: "completed" },
{ product: "Lamp", category: "Furniture", country: "DE", amount: 65, status: "pending" },
{ product: "Keyboard", category: "Electronics", country: "DE", amount: 89, status: "completed" }
]) How the Data Is Stored in MongoDB
After the insert, MongoDB keeps seven documents in orders. Run find() to see them:
db.orders.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
category | "Electronics" | Common group key |
amount | 1200 | Value we sum / average |
status | "completed" | Filter before grouping |
How It Works
- Reset once.
drop()keeps demos repeatable. - Mixed dimensions. Category and country are natural group keys.
- One pending row. Later examples filter it out with
$match.

