Example 1 — Sample Data
Imagine student Asha with skills: ["math", "quiz", "art"] and required: ["quiz", "math", "science"]. We save the document in students.
db.students.insertOne({
_id: 1,
name: "Asha",
skills: ["math", "quiz", "art"],
required: ["quiz", "math", "science"]
}); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps one document in students. Run find() to see it:
db.students.find() Read that document like this:
| Field in MongoDB | Value | Plain English |
|---|---|---|
_id | 1 | Document id |
name | "Asha" | Student name |
skills | ["math", "quiz", "art"] | What she has |
required | ["quiz", "math", "science"] | What the course needs |
skills: math quiz art
required: quiz math science
↓
shared: math quiz How It Works
- Insert once.
insertOneadds Asha’s document tostudents. - Two arrays ready. We will keep only values that appear in both.
- find() shows the same shape. Ready for Example 2.

