$multiply

The `$multiply` operator calculates the product of the specified input numerical values.

Syntax

{ $multiply: [ <listOfValues> ] }

Parameters

<listOfValues>stringrequired

A comma separated list of numerical values.

Examples

Sample Data

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

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
  }
]