Example 1 — Sample Data
Imagine six products with different prices, plus one gift card with null price for the default bucket.
db.products.insertMany([
{ _id: 1, name: "Pen", price: 2, score: 78 },
{ _id: 2, name: "Notebook", price: 8, score: 85 },
{ _id: 3, name: "Headphones", price: 45, score: 91 },
{ _id: 4, name: "Keyboard", price: 75, score: 88 },
{ _id: 5, name: "Monitor", price: 220, score: 94 },
{ _id: 6, name: "Laptop", price: 899, score: 96 },
{ _id: 7, name: "Gift card", price: null, score: 70 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps seven documents in products. Run find() to see them:
db.products.find() Read the important fields like this:
| Field | Example | Plain English |
|---|---|---|
name | "Pen" | Product label |
price | 2 … 899 / null | Value we will bucket |
score | 78 | Review score (for custom output) |
How It Works
- Insert once.
insertManyadds seven product documents toproducts. - Prices span several bands. Cheap items, mid-tier, expensive, and one
null. - find() shows the same shape. Ready for
$bucketnext.

