Example 1 — Sample Data
Imagine five records where value is sometimes a number, sometimes a string, and sometimes another BSON type. That mix is common in messy imports.
db.records.insertMany([
{ _id: 1, label: "Score A", value: 95 },
{ _id: 2, label: "Score B", value: "88" },
{ _id: 3, label: "Tags", value: ["mongo", "db"] },
{ _id: 4, label: "Empty", value: null },
{ _id: 5, label: "Meta", value: { active: true } }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps five documents in records. Run find() to see them:
db.records.find() Read the important fields like this:
| Field | Example | BSON type |
|---|---|---|
value | 95 | int |
value | "88" | string |
value | ["mongo", "db"] | array |
value | null | null |
value | { active: true } | object |
How It Works
- Insert once.
insertManyadds five mixed-type documents torecords. - Types are stored as written. Quotes make
"88"a string; bare95is numeric. - find() shows the same shape. Ready for query and aggregation
$typenext.

