$pow
The `$pow` operator calculates the value of a number raised to a specified exponent.
Syntax
{ $pow: [ <number>, <exponent> ] }
Parameters
<number>
stringrequiredThe base number to be raised to the exponent.
<exponent>
stringrequiredThe exponent to raise the base number to.
Examples
Calculate the square of total sales volume
Calculate the square of the sales volume using the $pow operator.
Query:
db.stores.aggregate([
{ $match: { company: { $in: ["First Up Consultants"] } } },
{
$project: {
company: 1,
"sales.revenue": 1,
fullSalesSquare: { $pow: ["$sales.revenue", 2] }
}
}
])
Output:
[
{
"_id": "39acb3aa-f350-41cb-9279-9e34c004415a",
"sales": { "revenue": 279183 },
"company": "First Up Consultants",
"fullSalesSquare": 77943194489
}
]