Create four synthetic orders
Run this in mongosh against a disposable development server with MongoDB 5.0 or later. Use an empty practice database named keplergrid_daily_orders. The order times are BSON Dates and the amounts are integer cents.
const practice = db.getSiblingDB("keplergrid_daily_orders");
practice.orders.insertMany([
{ _id: "O-101", customerId: "C-100",
placedAt: new Date("2026-06-10T23:30:00Z"), totalCents: 1200 },
{ _id: "O-102", customerId: "C-100",
placedAt: new Date("2026-06-11T00:30:00Z"), totalCents: 800 },
{ _id: "O-103", customerId: "C-100",
placedAt: new Date("2026-06-11T00:30:00Z"), totalCents: 700 },
{ _id: "O-201", customerId: "C-200",
placedAt: new Date("2026-06-11T04:15:00Z"), totalCents: 900 }
]);
Count and sum orders for each UTC day
Connect KeplerGrid to the practice server using a Read only connection. Open keplergrid_daily_orders.orders, select Aggregation → JSON, paste this pipeline, and choose Run pipeline.
[
{ "$group": {
"_id": { "$dateTrunc": {
"date": "$placedAt",
"unit": "day",
"timezone": "UTC"
} },
"orderCount": { "$sum": 1 },
"totalCents": { "$sum": "$totalCents" }
} },
{ "$sort": { "_id": 1 } }
]
Each row represents one day. Its _id is the instant that day starts. orderCount adds one per order and totalCents adds the stored amounts. Switch to Stages and select $group to compare the four orders in Input with the two buckets in Output.
Change the reporting time zone
Return to JSON, change "timezone": "UTC" to "timezone": "America/New_York", and run the pipeline again. In this June example, midnight in New York is 04:00 UTC. The two orders at 00:30 UTC on June 11 therefore contribute to the June 10 bucket in New York.
| Reporting day | Bucket start in UTC | Orders | Total cents |
|---|---|---|---|
| June 10, UTC | Jun 10, 00:00 | 1 | 1200 |
| June 11, UTC | Jun 11, 00:00 | 3 | 2400 |
| June 10, New York | Jun 10, 04:00 | 3 | 2700 |
| June 11, New York | Jun 11, 04:00 | 1 | 900 |
Use the named time zone for reports that span daylight saving changes. If you later add a date-range filter before $group, convert both reporting boundaries into UTC instants so the filter and buckets use the same calendar.
Use the same fixture to find the latest order per customer. You can also export your daily totals to CSV or Extended JSON.
To compare two timestamps on each document, measure the difference with $dateDiff.
To keep individual orders and add their cumulative values, calculate a running total per customer.