Example 1 — Sample Data
Imagine five students. Each document has a class, student name, and score.
db.scores.insertMany([
{ class: "A", student: "Sam", score: 90 },
{ class: "A", student: "Ana", score: 70 },
{ class: "A", student: "Lee", score: 85 },
{ class: "B", student: "Mia", score: 60 },
{ class: "B", student: "Omar", score: 95 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps 5 documents in scores. Run find() to see them:
db.scores.find() Read each document like this:
| Field in MongoDB | Meaning | Example |
|---|---|---|
class | Class / group name | "A" |
student | Student name | "Ana" |
score | Test score | 70 |
Class A scores: Sam 90, Ana 70, Lee 85
Class B scores: Mia 60, Omar 95
Next: $bottom finds the lowest-ranked student per class. How It Works
- Insert once. The sample command adds 5 documents to
scores. - MongoDB stores fields as written. Each document keeps the same field names and values you inserted.
- find() shows the same shape. What you inserted is what you get back—ready for
$bottomin the next examples.
With sortBy: { score: -1 }, class A’s bottom is Ana (70); class B’s bottom is Mia (60).

