Hướng dẫn sum and multiply mongodb
Docs Home → MongoDB Manual $multiply
Multiplies numbers together and returns the result. Pass the arguments to The
The arguments can be any valid expression as long as they resolve to numbers. For more information on expressions, see Expressions. Consider a
The following aggregation uses the
The operation returns the following results:
Docs Home → MongoDB Manual $sum Changed in version 5.0. Calculates and returns the collective sum of numeric values.
In MongoDB 3.2 and earlier, When used in the When used in
other supported stages,
For more information on expressions, see Expressions. The result will have the same type as the input except when it cannot be represented accurately in that type. In these cases:
If used on a field that contains
both numeric and non-numeric values, If used on a field that does not exist in any document in the collection, If all operands are non-numeric, In the In the other supported stages:
Consider a
Grouping the documents by the day and the year of the
The operation returns the following results:
Using
The operation returns:
The
TipSee also:A collection
The following example uses the
The operation results in the following documents:
New in version 5.0. Create a
This example uses
In the example:
In this output, the sum of the
|