-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
isoDayOfWeek.txt
103 lines (65 loc) · 2 KB
/
isoDayOfWeek.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
===========================
$isoDayOfWeek (aggregation)
===========================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. expression:: $isoDayOfWeek
.. versionadded:: 3.4
Returns the weekday number in ISO 8601 format, ranging from
``1`` (for Monday) to ``7`` (for Sunday).
:expression:`$isoDayOfWeek` has the following
:ref:`operator expression syntax <aggregation-expressions>`:
.. code-block:: javascript
{ $isoDayOfWeek: <date expression> }
.. include:: /includes/fact-iso-date-objects.rst
Behavior
--------
.. list-table::
:header-rows: 1
:widths: 90 10
* - Example
- Result
* - ``{ $isoDayOfWeek: new Date("2016-01-01") }``
- 5
* - ``{ $isoDayOfWeek: new Date("Jan 7, 2003") }``
- 2
* - ``{ $isoDayOfWeek: new Date("August 14, 2011") }``
- 7
* - ``{ $isoDayOfWeek: ISODate("1998-11-07T00:00:00Z") }``
- 6
* - ``{ $isoDayOfWeek: "March 28, 1976" }``
- ``error``
* - ``{ $isoDayOfWeek: "2009-04-09" }``
- ``error``
.. note:: ``$isoDayOfWeek`` cannot take a string as an argument.
Example
-------
A collection called ``birthdays`` contains the following documents:
.. code-block:: javascript
{ "_id" : 1, "name" : "Betty", "birthday" : ISODate("1993-09-21T00:00:00Z") }
{ "_id" : 2, "name" : "Veronica", "birthday" : ISODate("1981-11-07T00:00:00Z") }
The following operation returns the weekday number for each
``birthday`` field.
.. code-block:: javascript
db.dates.aggregate( [
{
$project: {
_id: 0,
name: "$name",
dayOfWeek: { $isoDayOfWeek: "$birthday" }
}
}
] )
The operation returns the following results:
.. code-block:: javascript
{ "name" : "Betty", "dayOfWeek" : 2 }
{ "name" : "Veronica", "dayOfWeek" : 6 }
.. seealso::
- :doc:`/reference/operator/aggregation/isoWeekYear`
- :doc:`/reference/operator/aggregation/isoWeek`