Example 1 — Sample Data
Imagine three students: Asha (85), Ben (72), and Cara (80—exactly on the line). We save them in students.
db.students.insertMany([
{ _id: 1, name: "Asha", score: 85 },
{ _id: 2, name: "Ben", score: 72 },
{ _id: 3, name: "Cara", score: 80 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in students. Run find() to see them:
db.students.find() Read those documents like this:
| Field | Asha | Ben | Cara |
|---|---|---|---|
_id | 1 | 2 | 3 |
name | "Asha" | "Ben" | "Cara" |
score | 85 | 72 | 80 |
Threshold line at 80:
Ben 72 ..... Cara 80 ..... Asha 85
|
score ≤ 80 ?
Ben → yes
Cara → yes (equals count)
Asha → no How It Works
- Insert once.
insertManyadds three student documents tostudents. - Include the boundary. Cara’s score is exactly
80—key for$ltevs$lt. - find() shows all rows. The next example keeps scores at or below 80.

