On this page本页内容
$add
¶Adds numbers together or adds numbers and a date. 将数字相加或将数字和日期相加。If one of the arguments is a date, 如果其中一个参数是日期,$add
treats the other arguments as milliseconds to add to the date.$add
将其他参数视为要添加到日期的毫秒。
The $add
expression has the following syntax:$add
表达式语法如下所示:
The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. 参数可以是任何有效的表达式,只要它们解析为所有数字或数字和日期。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
The following examples use a 以下示例将sales
collection with the following documents:sales
集合与以下文档一起使用:
The following aggregation uses the 以下聚合使用$add
expression in the $project
pipeline to calculate the total cost:$project
管道中的$add
表达式来计算总成本:
The operation returns the following results:操作返回以下结果:
The following aggregation uses the 下面的聚合使用$add
expression to compute the billing_date
by adding 3*24*60*60000
milliseconds (i.e. 3 days) to the date
field :$add
表达式通过向日期字段添加3*24*60*60000
毫秒(即3天)来计算billing_date
(账单日期):
The operation returns the following results:操作返回以下结果: