Example 1 — Sample Data
Imagine three order lines with product, price, quantity, and a customer first/last name.
db.orders.insertMany([
{
_id: 1,
product: "Keyboard",
price: 45,
quantity: 2,
firstName: "Sam",
lastName: "Lee"
},
{
_id: 2,
product: "Mouse",
price: 25,
quantity: 1,
firstName: "Alex",
lastName: "Kim"
},
{
_id: 3,
product: "Monitor",
price: 180,
quantity: 1,
firstName: "Jordan",
lastName: "Wu"
}
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in orders. Run find() to see them:
db.orders.find() Read each document like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
product | "Keyboard" | Item name |
price | 45 | Unit price |
quantity | 2 | Units ordered |
firstName / lastName | Sam / Lee | Customer name parts |
How It Works
- Insert once.
insertManyadds three order documents toorders. - Fields stay as written. Price and quantity are numbers; names are strings.
- find() shows the same shape. Ready for
$addFieldsnext.

