Definition定义
$isoWeekReturns the week number in ISO 8601 format, ranging from以ISO 8601格式返回周数,范围从1to53. Week numbers start at1with the week (Monday through Sunday) that contains the year's first Thursday.1到53。周数从包含一年中第一个星期四的周(周一至周日)的1开始。The$isoWeekexpression has the following operator expression syntax:$isoWeek表达式具有以下运算符表达式语法:{ $isoWeek: <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 Offset+/-[hh]:[mm], e.g. "+04:45"
+/-[hh][mm], e.g. "-0530"
+/-[hh], e.g. "+03"
Behavior行为
| 1 |
| 53 |
| 32 |
| 45 |
| 44 |
| error |
| error |
| error |
Note
$isoWeek cannot take a string as an argument.$isoWeek不能接受字符串作为参数。
Example示例
A collection called 称为deliveries contains the following documents:deliveries(交付)的集合包含以下文档:
db.deliveries.insertMany( [
{ _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 }
]