$exp

The `$exp` operator returns the value of e raised to the specified exponent. The mathematical constant e is approximately equal to 2.71828.

Syntax

{ $exp: <exponent> }

Parameters

<exponent>stringrequired

Any valid expression that resolves to a number.

Examples

Sample Data

{
  "_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
  "sales": { "totalSales": 75670 }
}

Calculate exponential growth rate

Calculate the exponential growth rate of total sales volume by 10% and 20% using the $exp operator.

Query:

db.stores.aggregate([
  { $match: { _id: "40d6f4d7-50cd-4929-9a07-0a7a133c2e74" } },
  {
    $project: {
      name: 1,
      currentSales: "$sales.totalSales",
      projectedGrowth: {
        oneYear: { $multiply: ["$sales.totalSales", { $exp: 0.1 }] },
        twoYears: { $multiply: ["$sales.totalSales", { $exp: 0.2 }] }
      }
    }
  }
])

Output:

[
  {
    "_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
    "name": "Proseware, Inc. | Home Entertainment Hub",
    "currentSales": 151864,
    "projectedGrowth": { "oneYear": 167809.93, "twoYears": 185304.95 }
  }
]