On this page本页内容
$isoWeek
Returns the week number in ISO 8601 format, ranging from 以ISO 8601格式返回周数,范围从1
to 53
. 1
到53
。Week numbers start at 周数从1
with the week (Monday through Sunday) that contains the year's first Thursday.1
开始,周(周一到周日)包含一年的第一个星期四。
The $isoWeek
expression has the following operator expression syntax:$isoWeek
表达式具有以下运算符表达式语法:
{ $isoWeek: <dateExpression> }
The argument can be:参数可以是:
A document with this format:具有以下格式的文档:
{ date: <dateExpression>, timezone: <tzExpression> }
date | <dateExpression> | ||||||
timezone |
|
{ $isoWeek: { date: new Date("Jan 4, 2016") } } | 1 |
{ $isoWeek: new Date("2016-01-01") } | 53 |
{ $isoWeek: { date: new Date("August 14, 2011"), timezone: "America/Chicago" } } | 32 |
{ $isoWeek: ISODate("1998-11-02T00:00:00Z") } | 45 |
{ $isoWeek: { date: ISODate("1998-11-02T00:00:00Z"), timezone: "-0500" } } | 44 |
{ $isoWeek: "March 28, 1976" } | error |
{ $isoWeek: Date("2016-01-01") } | error |
{ $isoWeek: "2009-04-09" } | error |
$isoWeek
不能将字符串作为参数。A collection called 称为deliveries
contains the following documents:deliveries
的集合包含以下文档:
{ "_id" : 1, "date" : ISODate("2006-10-24T00:00:00Z"), "city" : "Boston" } { "_id" : 2, "date" : ISODate("2011-08-18T00:00:00Z"), "city" : "Detroit" }
The following operation returns the week number for each 以下操作返回每个date
field.date
字段的周数。
db.deliveries.aggregate( [ { $project: { _id: 0, city: "$city", weekNumber: { $isoWeek: "$date" } } } ] )
The operation returns the following results:该操作返回以下结果:
{ "city" : "Boston", "weekNumber" : 43 } { "city" : "Detroit", "weekNumber" : 33 }