- $add: Adds two or more numbers together. The $add operator can also concatenate strings.
- $subtract: Subtracts one number from another.
- $divide: Divides one number by another.
- $mod: Computes the remainder of dividing one number by another.
- $ceil: Rounds a number up to the nearest integer.
- $floor: Rounds a number down to the nearest integer.
- $abs: Computes the absolute value of a number.
- $sqrt: Computes the square root of a number.
- $pow: Raises a number to a specified power.
- $exp: Computes the natural exponential function of a number.
- $log: Computes the natural logarithm of a number.
- $ln: Computes the base-10 logarithm of a number.
Example
db.products.aggregate([ { $project:{ product_name:1, price:1, quantity:1, total:{ $multiply:["$sale_price","$quantity"] }, discount:{ $subtract:["$price","$sale_price"]} } } ])