Example 1 — Sample Data
Imagine four user profiles. Some have tags as an array, one has a string, and one has no tags field.
db.profiles.insertMany([
{ _id: 1, name: "Ada", tags: ["js", "db"] },
{ _id: 2, name: "Lin", tags: "admin" },
{ _id: 3, name: "Sam", tags: [] },
{ _id: 4, name: "Kai" }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps four documents in profiles. Run find() to see them:
db.profiles.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | Profile id for this lesson |
name | "Ada" | User name |
tags | ["js", "db"] or "admin" | Sometimes an array, sometimes not |
Ada tags: ["js", "db"] → array? yes
Lin tags: "admin" → array? no
Sam tags: [] → array? yes (empty)
Kai (no tags) → array? no How It Works
- Insert once.
insertManyadds four profile documents. - MongoDB keeps the types you wrote. Arrays stay arrays; strings stay strings.
- find() shows the same shape. What you inserted is what you get back—ready for
$isArraynext.

