Example 1 — Sample Data
Imagine two sales with precise timestamps. We save them in a collection named sales.
db.sales.insertMany([
{
_id: 1,
item: "abc",
price: 10,
quantity: 2,
date: ISODate("2014-01-01T08:15:39.736Z")
},
{
_id: 2,
item: "xyz",
price: 20,
quantity: 1,
date: ISODate("2016-01-01T12:01:00.000Z")
}
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps two documents in sales. Run find() to see them:
db.sales.find() Read one document like this:
| Field in MongoDB | Value (doc 1) | Plain English |
|---|---|---|
_id | 1 | Document id |
item | "abc" | Product code |
date | …T08:15:39.736Z | Sale time (BSON Date) |
How It Works
- Insert once.
insertManyadds two sale documents tosales. - Dates are BSON Date. Use
ISODate(...), not plain strings. - find() shows the same shape. Ready for
$secondnext.

