Example 1 — Sample Data
Imagine six sales with different amounts, plus one gift-wrap row with null amount (we will filter it out before bucketing).
db.sales.insertMany([
{ _id: 1, item: "Sticker pack", amount: 12, region: "East" },
{ _id: 2, item: "T-shirt", amount: 35, region: "West" },
{ _id: 3, item: "Hoodie", amount: 68, region: "East" },
{ _id: 4, item: "Laptop bag", amount: 95, region: "West" },
{ _id: 5, item: "Sneakers", amount: 120, region: "West" },
{ _id: 6, item: "Jacket", amount: 185, region: "East" },
{ _id: 7, item: "Gift wrap", amount: null, region: "East" }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps seven documents in sales. Run find() to see them:
db.sales.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
item | "Hoodie" | Product sold |
amount | 12 … 185 / null | Value we will auto-bucket |
region | "East" | Sales region (unused in these demos) |
How It Works
- Insert once.
insertManyadds seven sale documents tosales. - Amounts span a range. Numeric values run from 12 to 185; one row is
null. - find() shows the same shape. Ready for
$bucketAutonext.

