Example 1 — Sample Data
Three flags in different shapes: number 0, number 1, and the string "false".
db.flags.insertMany([
{ _id: 1, name: "zero", flag: 0 },
{ _id: 2, name: "one", flag: 1 },
{ _id: 3, name: "text-false", flag: "false" }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in flags. Run find() to see them:
db.flags.find() Read the rows like this:
| Field | Examples | Plain English |
|---|---|---|
_id | 1, 2, 3 | Document id |
name | "zero", … | Label for the lesson |
flag | 0, 1, "false" | Value we will convert |
How It Works
- Insert three docs.
insertManystores mixed flag types on purpose. - Types stay as written.
0and1are numbers;"false"is a string. - Ready to convert. The next example runs
$toBoolonflag.

