Example 1 — Sample Data
Six orders across three statuses and two regions—enough variety for filtered counts and group counting.
db.orders.drop()
db.orders.insertMany([
{ product: "Keyboard", amount: 45, status: "shipped", region: "East" },
{ product: "Mouse", amount: 25, status: "pending", region: "West" },
{ product: "Monitor", amount: 220, status: "shipped", region: "East" },
{ product: "Webcam", amount: 60, status: "pending", region: "East" },
{ product: "Headset", amount: 80, status: "shipped", region: "West" },
{ product: "Dock", amount: 95, status: "cancelled", region: "West" }
]) How the Data Is Stored in MongoDB
After the insert, MongoDB keeps six documents in orders. Run find() to see them:
db.orders.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
status | "shipped" | Order state we often filter on |
amount | 45 … 220 | Order total for high-value filters |
region | "East" | Region used when counting groups |
How It Works
- Reset once.
drop()keeps the demo repeatable. - Insert six orders. Mixed statuses give useful
$matchcounts. - Ready for counting. Next examples tally these rows (or groups of them).

