$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>
stringrequiredAny valid expression that resolves to a number.
Examples
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 }
}
]