Example 1 — Sample Data
Imagine four orders. Each has a store, a city, and an amount. Store A visits New York twice—perfect for showing how $push keeps duplicates.
db.orders.insertMany([
{ store: "A", city: "New York", amount: 120 },
{ store: "A", city: "New York", amount: 40 },
{ store: "A", city: "Chicago", amount: 90 },
{ store: "B", city: "New York", amount: 75 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps 4 documents in orders. Run find() to see them:
db.orders.find() Read each document like this:
| Field in MongoDB | Meaning | Example |
|---|---|---|
store | Which store made the order | "A" |
city | City for that order | "New York" |
amount | Order total | 120 |
Store A cities in order:
New York, New York, Chicago
$push keeps every value — including duplicates. How It Works
- Insert once. The sample command adds 4 documents to
orders. - MongoDB stores fields as written. Each document keeps the same field names and values you inserted.
- find() shows the same shape. What you inserted is what you get back—ready for
$pushin the next examples.

