$isoWeekYear (aggregation)
정의
$isoWeekYear
Returns 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.
$isoWeekYear
표현식에는 다음과 같은 연산자 표현식 구문이 있습니다.{ $isoWeekYear: <dateExpression> } 인수는 다음과 같습니다:
이 형식의 문서입니다:
{ date: <dateExpression>, timezone: <tzExpression> } 필드설명date
timezone
선택 사항. 작업 결과의 표준 시간대입니다. 은 Olson 표준 시간대
<tzExpression>
식별자 형식의 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"
행동
예시 | 결과 | ||||
---|---|---|---|---|---|
| 2015 | ||||
| 2003 | ||||
| 2017 | ||||
| 2016 | ||||
| 2024 | ||||
|
| ||||
|
| ||||
|
|
참고
$isoWeekYear cannot take a string as an argument.
예시
컬렉션 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.
db.anniversaries.aggregate( [ { $project: { yearNumber: { $isoWeekYear: "$date" } } } ] )
이 연산은 다음과 같은 결과를 반환합니다.
{ "_id" : 1, "yearNumber" : 2015 } { "_id" : 2, "yearNumber" : 2016 } { "_id" : 3, "yearNumber" : 2015 } { "_id" : 4, "yearNumber" : 2014 }