On this page本页内容
$dayOfMonth
¶Returns the day of the month for a date as a number between 1 and 31.以1到31之间的数字返回日期的月份。
The $dayOfMonth
expression has the following operator expression syntax:$dayOfMonth
表达式具有以下运算符表达式语法:
Changed in version 3.6.在版本3.6中更改。
The argument must be a valid expression that resolves to one of the following:参数必须是解析为以下之一的有效表达式:
New in version 3.6.版本3.6中的新功能。
date |
<dateExpression> must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID.<dateExpression> 必须是解析为日期、时间戳或ObjectID的有效表达式。 | ||||||
timezone |
|
Result | |
---|---|
1 | |
7 | |
14 | |
7 | |
6 | |
error | |
error | |
error |
Note
$dayOfMonth
cannot take a string as an argument.不能将字符串作为参数。
Consider a 考虑一个sales
collection with the following document:sales
集合带有以下文档:
The following aggregation uses the 以下聚合使用$dayOfMonth
and other date operators to break down the date
field:$dayOfMonth
和其他日期运算符来分解date
字段:
The operation returns the following result:操作返回以下结果: