Example 1 — Sample Data
Imagine five survey rows. Each document has a responses array. We save them in a collection named survey.
db.survey.insertMany([
{ _id: 1, responses: [ true ] },
{ _id: 2, responses: [ true, false ] },
{ _id: 3, responses: [] },
{ _id: 4, responses: [ 0 ] },
{ _id: 5, responses: [ [ false ] ] }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps five documents in survey. Run find() to see them:
db.survey.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 … 5 | Survey id for this lesson |
responses | [ true, false ] | List of answer values to test |
Any-true check (left → right, stop at first truthy):
[ true, false ] → true stops → true
[ ] → nothing → false
[ 0 ] → 0 is falsy → false
[ [ false ] ] → array truthy → true
Think: "is there at least one yes?" How It Works
- Insert once.
insertManyadds five survey documents. - MongoDB stores arrays as written. Each
responsesvalue stays an array of elements. - find() shows the same shape. What you inserted is what you get back—ready for
$anyElementTruenext.

