Example 1 — Sample Data
Imagine four inventory items. Each document has an item code and a quantity. We save them in a collection named inventory.
db.inventory.insertMany([
{ _id: 1, item: "abc1", qty: 300 },
{ _id: 2, item: "abc2", qty: 200 },
{ _id: 3, item: "xyz1", qty: 250 },
{ _id: 4, item: "VWZ2", qty: 180 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps four documents in inventory. Run find() to see them:
db.inventory.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 … 4 | Document id for this lesson |
item | "abc1" | Product / SKU code |
qty | 300 | Quantity on hand |
Discount rule:
qty >= 250 → discount 30 (bulk)
qty < 250 → discount 20 (normal)
300, 250 → then → 30
200, 180 → else → 20 How It Works
- Insert once.
insertManyadds four inventory documents. - MongoDB stores fields as written. Each row keeps
itemandqtyas plain values. - find() shows the same shape. What you inserted is what you get back—ready for
$condnext.

