Example 1 — Sample Data
Imagine three orders: one in 2023 and two in 2024. That mix makes yearly grouping easy to see.
db.orders.insertMany([
{
_id: 1,
customer: "Alice",
orderDate: ISODate("2023-11-20T10:00:00Z"),
amount: 450
},
{
_id: 2,
customer: "Bob",
orderDate: ISODate("2024-03-15T14:30:00Z"),
amount: 320
},
{
_id: 3,
customer: "Carol",
orderDate: ISODate("2024-12-01T09:00:00Z"),
amount: 890
}
]); 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 |
|---|---|---|
_id | 1 | Document id (row number for this lesson) |
customer | "Alice" | Who placed the order |
orderDate | 2023-11-20 | Order timestamp (BSON Date) |
amount | 450 | Order total |
How It Works
- Insert once.
insertManyadds three order documents toorders. - Dates are BSON Dates.
ISODate(...)stores a real date, not a string. - find() shows the same shape. Ready for
$yearin the next examples.

