$isoWeek(集計)
定義
$isoWeek
Returns the week number in ISO 8601 format, ranging from
1
to53
. Week numbers start at1
with the week (Monday through Sunday) that contains the year's first Thursday.{ $isoWeek: <dateExpression> } 引数は次のとおりです。
次の形式のドキュメント:
{ date: <dateExpression>, timezone: <tzExpression> } フィールド説明date
timezone
Optional.
操作結果のタイムゾーン。<tzExpression>
は、有効な 式 であり、 Olson タイムゾーン識別子 として形式された string に変換される必要があります。 または UTC オフセット 。timezone
が指定されていない場合、結果はUTC
に表示されます。形式例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"
動作
例 | 結果 | ||||
---|---|---|---|---|---|
| 1 | ||||
| 53 | ||||
| 32 | ||||
| 45 | ||||
| 44 | ||||
|
| ||||
|
| ||||
|
|
注意
$isoWeek cannot take a string as an argument.
例
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.
db.deliveries.aggregate( [ { $project: { _id: 0, city: "$city", weekNumber: { $isoWeek: "$date" } } } ] )
この操作は次の結果を返します。
[ { city: "Boston", weekNumber: 43 }, { city: "Detroit", weekNumber: 33 } ]