Example 1 — Sample Data
Imagine three orders in June 2024. Two fall in the same Sunday-based week; one falls in the next week.
db.orders.insertMany([
{
_id: 1,
customer: "Alice",
orderDate: ISODate("2024-06-10T14:30:00Z"),
amount: 120
},
{
_id: 2,
customer: "Bob",
orderDate: ISODate("2024-06-15T09:00:00Z"),
amount: 85.5
},
{
_id: 3,
customer: "Carol",
orderDate: ISODate("2024-06-17T16:45:00Z"),
amount: 210
}
]); 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 | 2024-06-10 | Order timestamp (BSON Date) |
amount | 120 | 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
$weekin the next examples.

