Definition定义
$isoWeekYearReturns the year number in ISO 8601 format. The year starts with the Monday of week 1 and ends with the Sunday of the last week.以ISO 8601格式返回年份号。一年从第1周的星期一开始,到最后一周的星期日结束。The$isoWeekYearexpression has the following operator expression syntax:$isoWeekYear表达式具有以下运算符表达式语法:{ $isoWeekYear: <dateExpression> }The argument can be:参数可以是:An expression that resolves to a Date, a Timestamp, or an ObjectID.解析为Date、Timestamp或ObjectID的表达式。A document with this format:具有此格式的文档:{ date: <dateExpression>, timezone: <tzExpression> }Field字段Description描述dateThe date to which the operator is applied.运算符的应用日期。<dateExpression>must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID.<dateExpression>必须是解析为Date、Timestamp或ObjectID的有效表达式。timezoneOptional.可选。The timezone of the operation result.操作结果的时区。<tzExpression>must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset.<tzExpression>必须是解析为奥尔森时区标识符或UTC偏移格式的字符串的有效表达式。If no如果没有提供timezoneis provided, the result is in UTC.timezone,则结果为UTC。Format格式Examples示例Olson Timezone Identifier奥尔森时区标识符"America/New_York"
"Europe/London"
"GMT"UTC OffsetUTC偏移+/-[hh]:[mm], e.g. "+04:45"
+/-[hh][mm], e.g. "-0530"
+/-[hh], e.g. "+03"
Behavior行为
| 2015 |
| 2003 |
| 2017 |
| 2016 |
| 2024 |
| error |
| error |
| error |
Note
$isoWeekYear cannot take a string as an argument.$isoWeekYear不能接受字符串作为参数。
Example示例
A collection called 一个名为anniversaries contains the following documents:anniversaries(周年纪念)的集合包含以下文件:
{ "_id" : 1, "date" : ISODate("2016-01-01T00:00:00Z") }
{ "_id" : 2, "date" : ISODate("2016-01-04T00:00:00Z") }
{ "_id" : 3, "date" : ISODate("2015-01-01T00:00:00Z") }
{ "_id" : 4, "date" : ISODate("2014-04-21T00:00:00Z") }
The following operation returns the year number in ISO 8601 format for each 以下操作为每个date field.date字段返回ISO 8601格式的年份号。
db.anniversaries.aggregate( [
{
$project: {
yearNumber: { $isoWeekYear: "$date" }
}
}
] )
The operation returns the following results:该操作返回以下结果:
{ "_id" : 1, "yearNumber" : 2015 }
{ "_id" : 2, "yearNumber" : 2016 }
{ "_id" : 3, "yearNumber" : 2015 }
{ "_id" : 4, "yearNumber" : 2014 }