Example 1 — Sample Data
Imagine three sales lines. Each has a price and a quantity. We save them in a collection named sales.
db.sales.insertMany([
{ _id: 1, item: "abc", price: 10, quantity: 2, date: ISODate("2014-03-01T08:00:00Z") },
{ _id: 2, item: "jkl", price: 20, quantity: 1, date: ISODate("2014-03-01T09:00:00Z") },
{ _id: 3, item: "xyz", price: 5, quantity: 10, date: ISODate("2014-03-15T09:00:00Z") }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in sales. Run find() to see them:
db.sales.find() Read one document like this:
| Field in MongoDB | Value (doc 1) | Plain English |
|---|---|---|
item | "abc" | Product code |
price | 10 | Unit price |
quantity | 2 | Units sold |
How It Works
- Insert once.
insertManyadds three sale documents tosales. - Two numbers per line.
priceandquantityare ready for$multiply. - find() shows the same shape. What you inserted is what you get back.

