On this page本页内容
$dayOfWeek
¶Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).以1(星期日)到7(星期六)之间的数字形式返回日期的星期几。
The $dayOfWeek
expression has the following operator expression syntax:$dayOfWeek
表达式具有以下运算符表达式语法:
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 | |
---|---|
6 | |
3 | |
1 | |
7 | |
6 | |
error | |
error | |
error |
Note
$dayOfWeek
cannot take a string as an argument.不能将字符串作为参数。
Consider a 考虑一个sales
collection with the following document:sales
集合带有以下文档:
The following aggregation uses the 以下聚合使用$dayOfWeek
and other date operators to break down the date
field:$dayOfWeek
和其他日期运算符来分解date
字段:
The operation returns the following result:操作返回以下结果: