Example 1 — Sample Data
Imagine three products: a cheap Pen, an out-of-stock Book, and an in-stock expensive Lamp.
db.products.insertMany([
{ _id: 1, name: "Pen", price: 5, inStock: true },
{ _id: 2, name: "Book", price: 15, inStock: false },
{ _id: 3, name: "Lamp", price: 25, inStock: true }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in products. Run find() to see them:
db.products.find() Read those documents like this:
| Field | Pen | Book | Lamp |
|---|---|---|---|
price | 5 | 15 | 25 |
inStock | true | false | true |
$or: cheap (< 10) OR out of stock
Pen → cheap ✓
Book → out of stock ✓
Lamp → neither ✗ How It Works
- Insert once.
insertManyadds three product documents toproducts. - Two different fields. Price and stock let us show
$oracross fields (where$inwould not fit). - find() shows all rows. The next example keeps only OR matches.

