Skip to content

Commit

Permalink
DOCSP-24188 Improve accounts example (#4057)
Browse files Browse the repository at this point in the history
* DOCSP-24188 clarifying account fields

* added commas

* formatting
  • Loading branch information
gmiller-mdb authored Jul 19, 2023
1 parent 5364a05 commit cd46d54
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/reference/operator/aggregation/exp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ A collection named ``accounts`` contains the following documents:

.. code-block:: javascript

{ _id: 1, rate: .08, pv: 10000 }
{ _id: 2, rate: .0825, pv: 250000 }
{ _id: 3, rate: .0425, pv: 1000 }
db.accounts.insertMany( [
{ _id: 1, interestRate: .08, presentValue: 10000 },
{ _id: 2, interestRate: .0825, presentValue: 250000 },
{ _id: 3, interestRate: .0425, presentValue: 1000 }
] )

The following example calculates the effective interest rate for
continuous compounding:

.. code-block:: javascript

db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$rate"}, 1 ] } } } ] )
db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$interestRate"}, 1 ] } } } ] )

The operation returns the following results:

.. code-block:: javascript
:copyable: false

{ "_id" : 1, "effectiveRate" : 0.08328706767495864 }
{ "_id" : 2, "effectiveRate" : 0.08599867343905654 }
Expand Down

0 comments on commit cd46d54

Please sign in to comment.