Example 1 — Sample Data
Imagine one cart named Office with four line items and different prices.
db.carts.insertOne({
_id: 1,
name: "Office",
items: [
{ name: "Pen", price: 80 },
{ name: "Book", price: 120 },
{ name: "Mug", price: 45 },
{ name: "Lamp", price: 200 }
]
}); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps one document in carts. Run find() to see it:
db.carts.find() Read that document like this:
| Field in MongoDB | Value | Plain English |
|---|---|---|
_id | 1 | Document id |
name | "Office" | Cart label |
items | array of 4 objects | Each object has name and price |
items array:
Pen 80 | Book 120 | Mug 45 | Lamp 200
|
v $filter (price >= 100)
|
Book 120 | Lamp 200 How It Works
- Insert once.
insertOneadds a single cart document tocarts. - Store an array.
itemsholds embedded objects—exactly what$filterexpects asinput. - find() shows the same shape. Ready for the filter examples next.

