Example 1 — Sample Data
Imagine four products. Some have a numeric price, one has a string price, and one has no price field.
db.products.insertMany([
{ _id: 1, name: "Mug", price: 12 },
{ _id: 2, name: "Notebook", price: "9.99" },
{ _id: 3, name: "Pen", price: 2.5 },
{ _id: 4, name: "Gift" }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps four 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 or "9.99" | Sometimes a number, sometimes a string |
Mug price: 12 → number? yes
Notebook price: "9.99" → number? no (string)
Pen price: 2.5 → number? yes
Gift (no price) → number? no How It Works
- Insert once.
insertManyadds four product documents. - MongoDB keeps the types you wrote. Numbers stay numbers; quoted values stay strings.
- find() shows the same shape. What you inserted is what you get back—ready for
$isNumbernext.

