Example 1 — Sample Data
Imagine four products with quantity and unit price. We will filter by inventory value: qty * price.
db.products.insertMany([
{ _id: 1, name: "Widget A", qty: 50, price: 25 },
{ _id: 2, name: "Widget B", qty: 10, price: 120 },
{ _id: 3, name: "Widget C", qty: 100, price: 8.5 },
{ _id: 4, name: "Widget D", qty: 5, price: 250 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps four documents in products. Run find() to see them:
db.products.find() Read each document like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | Document id (row number for this lesson) |
name | "Widget A" | Product name |
qty | 50 | Units in stock |
price | 25 | Unit price |
How It Works
- Insert once.
insertManyadds four product documents toproducts. - Fields stay numeric.
qtyandpriceare numbers so multiplication works in JS or in$multiply. - find() shows the same shape. Ready for
$whereand$exprnext.

