$sqrt
The `$sqrt` operator is used to calculate the square root of a specified number.
Syntax
{ $sqrt: <expression> }
Parameters
<expression>
stringrequiredAny valid expression that resolves to a number.
Examples
Calculate the square root of sales
Calculate the square root of the sales volumes for each store.
Query:
db.stores.aggregate([
{ $match: { company: { $in: ["First Up Consultants"] } } },
{
$project: {
name: 1,
"sales.revenue": 1,
sqrtFullSales: { $sqrt: "$sales.revenue" }
}
}
])
Output:
[
{
"_id": "c52c9f65-5b1a-4ef5-a7a2-d1af0426cbe4",
"name": "First Up Consultants | Jewelry Pantry - Nicolasberg",
"sales": { "revenue": 4624 },
"sqrtFullSales": 68
}
]