Example 1 — Sample Data
Imagine two classes. Math has matching array lengths; Science has an extra score so we can see shortest-length behavior.
db.students.insertMany([
{
_id: 1,
className: "Math 101",
names: ["Alice", "Bob", "Carol"],
scores: [92, 85, 78]
},
{
_id: 2,
className: "Science 201",
names: ["Dave", "Eve"],
scores: [88, 91, 95]
}
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps two documents in students. Run find() to see them:
db.students.find() Read each document like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
className | "Math 101" | Class label |
names | ["Alice", "Bob", "Carol"] | Student names (parallel column) |
scores | [92, 85, 78] | Scores aligned by the same index |
How It Works
- Insert once.
insertManyadds two class documents tostudents. - Arrays stay parallel. Index
0means Alice’s score is92. - find() shows the same shape. Ready for
$zipnext.

