Example 1 — Sample Data
Imagine three savings accounts. Each has an interest rate and a present value. We save them in a collection named accounts.
db.accounts.insertMany([
{ _id: 1, interestRate: 0.08, presentValue: 10000 },
{ _id: 2, interestRate: 0.0825, presentValue: 250000 },
{ _id: 3, interestRate: 0.0425, presentValue: 1000 }
]); How the Data Is Stored in MongoDB
After the insert, MongoDB keeps three documents in accounts. Run find() to see them:
db.accounts.find() Read one document like this:
| Field in MongoDB | Value (doc 1) | Plain English |
|---|---|---|
_id | 1 | Document id |
interestRate | 0.08 | Nominal rate (8%) |
presentValue | 10000 | Current balance |
How It Works
- Insert once.
insertManyadds three account documents toaccounts. - Rates are decimals.
0.08means 8%, not the number 8. - find() shows the same shape. What you inserted is what you get back—ready for
$expnext.

