Example 1 — Sample Data
Imagine six orders across stores A and B. Each document has a store, product, and amount.
db.orders.insertMany([
{ store: "A", product: "Laptop", amount: 1200 },
{ store: "A", product: "Mouse", amount: 25 },
{ store: "A", product: "Keyboard", amount: 75 },
{ store: "A", product: "Monitor", amount: 300 },
{ store: "B", product: "Laptop", amount: 1100 },
{ store: "B", product: "Headset", amount: 80 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps 6 documents in orders. Run find() to see them:
db.orders.find() Read each document like this:
| Field in MongoDB | Meaning | Example |
|---|---|---|
store | Which store | "A" |
product | What was sold | "Laptop" |
amount | Order amount | 1200 |
Store A order stream (as inserted):
Laptop, Mouse, Keyboard, Monitor
Next: $firstN keeps the first N values in that order. How It Works
- Insert once. The sample command adds 6 documents to
orders. - MongoDB stores fields as written. Each document keeps the same field names and values you inserted.
- find() shows the same shape. What you inserted is what you get back—ready for
$firstNin the next examples.

