Example 1 — Sample Data
Imagine three stores. Each has a location and an in_stock list of fruit. We save them in a collection named fruit.
db.fruit.insertMany([
{ _id: 1, location: "24th Street", in_stock: ["apples", "bananas", "oranges"] },
{ _id: 2, location: "36th Street", in_stock: ["bananas", "pears"] },
{ _id: 3, location: "82nd Street", in_stock: ["apples", "oranges"] }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in fruit. Run find() to see them:
db.fruit.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | Store id for this lesson |
location | "24th Street" | Store location label |
in_stock | ["apples", "bananas", ...] | Array of fruit names currently stocked |
Look for "bananas" in each list:
24th: apples, bananas, oranges → yes
36th: bananas, pears → yes
82nd: apples, oranges → no
$in asks only "present?" — not "where?" or "how many?" How It Works
- Insert once.
insertManyadds three store documents. - MongoDB stores arrays as written. Each
in_stockvalue is a list of strings. - find() shows the same shape. What you inserted is what you get back—ready for
$innext.

