Example 1 — Sample Data
Imagine three products with decimal prices. We save them in a collection named products.
db.products.insertMany([
{ _id: 1, name: "Mug", price: 12.346 },
{ _id: 2, name: "Pen", price: 2.5 },
{ _id: 3, name: "Book", price: 19.99 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in products. Run find() to see them:
db.products.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | Product id for this lesson |
name | "Mug" | Product name |
price | 12.346 | Number we will round |
Mug 12.346 → round @2 → 12.35
Pen 2.5 → round @0 → 2 (half-to-even)
Book 19.99 → round @0 → 20 How It Works
- Insert once.
insertManyadds three product documents. - Prices are numbers. Not strings—
$roundneeds a numeric type. - find() shows the same shape. What you inserted is what you get back—ready for
$roundnext.

