On this page本页内容
$isoDayOfWeek
Returns the weekday number in ISO 8601 format, ranging from 返回ISO 8601格式的工作日数字,范围从1
(for Monday) to 7
(for Sunday).1
(表示星期一)到7
(表示星期日)。
The $isoDayOfWeek
expression has the following operator expression syntax:$isoDayOfWeek
表达式具有以下运算符表达式语法:
{ $isoDayOfWeek: <dateExpression> }
The argument can be:参数可以是:
A document with this format:具有以下格式的文档:
{ date: <dateExpression>, timezone: <tzExpression> }
date | <dateExpression> | ||||||
timezone |
|
{ $isoDayOfWeek: new Date("2016-01-01") } | 5 |
{ $isoDayOfWeek: { date: new Date("Jan 7, 2003") } } | 2 |
{ $isoDayOfWeek: { date: new Date("August 14, 2011"), timezone: "America/Chicago" } } | 7 |
{ $isoDayOfWeek: ISODate("1998-11-07T00:00:00Z") } | 6 |
{ $isoDayOfWeek: { date: ISODate("1998-11-07T00:00:00Z"), timezone: "-0400" } } | 5 |
{ $isoDayOfWeek: "March 28, 1976" } | error |
{ $isoDayOfWeek: Date("2016-01-01") } | error |
{ $isoDayOfWeek: "2009-04-09" } | error |
$isoDayOfWeek
不能将字符串作为参数。A collection called 名为birthdays
contains the following documents:birthdays
的集合包含以下文档:
{ "_id" : 1, "name" : "Betty", "birthday" : ISODate("1993-09-21T00:00:00Z") } { "_id" : 2, "name" : "Veronica", "birthday" : ISODate("1981-11-07T00:00:00Z") }
The following operation returns the weekday number for each 以下操作返回每个birthday
field.birthday
字段的工作日编号。
db.dates.aggregate( [ { $project: { _id: 0, name: "$name", dayOfWeek: { $isoDayOfWeek: "$birthday" } } } ] )
The operation returns the following results:该操作返回以下结果:
{ "name" : "Betty", "dayOfWeek" : 2 } { "name" : "Veronica", "dayOfWeek" : 6 }