Example 1 — Sample Data
Imagine three notes. Two have messy trailing characters; one has a null text field.
db.notes.insertMany([
{ _id: 1, text: "hello " },
{ _id: 2, text: "code***" },
{ _id: 3, text: null }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in notes. Run find() to see them:
db.notes.find() Read those documents like this:
| Field in MongoDB | Example | Plain English |
|---|---|---|
_id | 1 | Note id for this lesson |
text | "hello " | String that may have trailing junk |
"hello " → trailing spaces
"code***" → trailing stars
null → stays null after $rtrim How It Works
- Insert once.
insertManyadds three note documents. - Trailing characters are real data. Spaces and
*are stored until you trim them. - find() shows the same shape. What you inserted is what you get back—ready for
$rtrimnext.

