$multiply
The `$multiply` operator calculates the product of the specified input numerical values.
Syntax
{ $multiply: [ <listOfValues> ] }
Parameters
<listOfValues>
stringrequiredA comma separated list of numerical values.
Examples
Multiply a field by a constant
Double the total sales for all stores by multiplying the sales field by 2.
Query:
db.stores.aggregate([
{ $match: { company: { $in: ["First Up Consultants"] } } },
{
$project: {
company: 1,
"sales.revenue": 1,
salesVolumeDoubled: { $multiply: ["$sales.revenue", 2] }
}
}
])
Output:
[
{
"_id": "39acb3aa-f350-41cb-9279-9e34c004415a",
"sales": { "revenue": 279183 },
"company": "First Up Consultants",
"salesVolumeDoubled": 558366
}
]