Example 1 — Sample Data
Imagine four users. Most have a favorites list; one has an empty list; one has no favorites field.
db.users.insertMany([
{ _id: 1, name: "dave123", favorites: ["chocolate", "cake", "apples"] },
{ _id: 2, name: "li", favorites: ["apples", "pie"] },
{ _id: 3, name: "ahn", favorites: [] },
{ _id: 4, name: "ty" }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps four documents in users. Run find() to see them:
db.users.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | User id for this lesson |
name | "dave123" | User name |
favorites | ["chocolate", "cake", "apples"] | Ordered list (first = earliest) |
dave123 favorites:
["chocolate", "cake", "apples"]
first ───────────────────► last
after $reverseArray:
["apples", "cake", "chocolate"]
last ───────────────────► first How It Works
- Insert once.
insertManyadds four user documents. - Order matters. Arrays keep the sequence you wrote—reverse will flip that sequence.
- find() shows the same shape. What you inserted is what you get back—ready for
$reverseArraynext.

