Example 1 — Sample Data
Seed five orders and one secondary index so storage and count stats have something meaningful to report.
db.orders.drop()
db.orders.createIndex({ customerId: 1 })
db.orders.insertMany([
{ customerId: "C001", product: "Keyboard", amount: 45, status: "shipped" },
{ customerId: "C002", product: "Mouse", amount: 25, status: "pending" },
{ customerId: "C001", product: "Monitor", amount: 220, status: "shipped" },
{ customerId: "C003", product: "Webcam", amount: 60, status: "pending" },
{ customerId: "C002", product: "Headset", amount: 80, status: "shipped" }
]) How the Data Is Stored in MongoDB
After the insert, MongoDB keeps five documents in orders. Run find() to see them:
db.orders.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
customerId | "C001" | Indexed customer key |
product | "Keyboard" | Item ordered |
amount | 45 | Order total |
How It Works
- Reset the collection.
drop()starts clean for repeatable demos. - Add an index.
customerIdgivesstorageStatsa second index to measure. - Insert five orders. Small sample—enough for count and size fields to be non-zero.

