Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (51 sloc) 1.63 KB
==================
$exp (aggregation)
==================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. expression:: $exp
.. versionadded:: 3.2
Raises Euler's number (i.e. *e* ) to the specified exponent and
returns the result.
:expression:`$exp` has the following syntax:
.. code-block:: javascript
{ $exp: <exponent> }
The ``<exponent>`` expression can be any valid :ref:`expression
<aggregation-expressions>` as long as it resolves to a number. For
more information on expressions, see :ref:`aggregation-expressions`.
Behavior
--------
.. include:: /includes/extracts/agg-expression-null-operand-exp.rst
.. list-table::
:header-rows: 1
:widths: 85 15
* - Example
- Results
* - ``{ $exp: 0 }``
- ``1``
* - ``{ $exp: 2 }``
- ``7.38905609893065``
* - ``{ $exp: -2 }``
- ``0.1353352832366127``
Example
-------
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 }
The following example calculates the effective interest rate for
continuous compounding:
.. code-block:: javascript
db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$rate"}, 1 ] } } } ] )
The operation returns the following results:
.. code-block:: javascript
{ "_id" : 1, "effectiveRate" : 0.08328706767495864 }
{ "_id" : 2, "effectiveRate" : 0.08599867343905654 }
{ "_id" : 3, "effectiveRate" : 0.04341605637367807 }
You can’t perform that action at this time.