$isoDayOfWeek
The $isoDayOfWeek operator in Amazon DocumentDB returns the ISO day of the week for a date as an integer value. The ISO week date system defines each week starting on a Monday and ending on a Sunday, with week 1 being the week that contains the year's first Thursday.
Parameters
-
expression: The date expression for which to return the ISO day of the week.
Example (MongoDB Shell)
The following example demonstrates how to use the $isoDayOfWeek operator to retrieve the ISO day of the week for a set of event documents.
Create sample documents
db.events.insertMany([ { _id: 1, eventDate: ISODate("2023-04-01T12:00:00Z") }, { _id: 2, eventDate: ISODate("2023-04-02T12:00:00Z") }, { _id: 3, eventDate: ISODate("2023-04-03T12:00:00Z") }, { _id: 4, eventDate: ISODate("2023-04-04T12:00:00Z") }, { _id: 5, eventDate: ISODate("2023-04-05T12:00:00Z") }, { _id: 6, eventDate: ISODate("2023-04-06T12:00:00Z") }, { _id: 7, eventDate: ISODate("2023-04-07T12:00:00Z") } ]);
Query example
db.events.aggregate([ { $project: { _id: 1, eventDate: 1, isoDayOfWeek: { $isoDayOfWeek: "$eventDate" } }} ]);
Output
[
{ "_id": 1, "eventDate": ISODate("2023-04-01T12:00:00Z"), "isoDayOfWeek": 6 },
{ "_id": 2, "eventDate": ISODate("2023-04-02T12:00:00Z"), "isoDayOfWeek": 7 },
{ "_id": 3, "eventDate": ISODate("2023-04-03T12:00:00Z"), "isoDayOfWeek": 1 },
{ "_id": 4, "eventDate": ISODate("2023-04-04T12:00:00Z"), "isoDayOfWeek": 2 },
{ "_id": 5, "eventDate": ISODate("2023-04-05T12:00:00Z"), "isoDayOfWeek": 3 },
{ "_id": 6, "eventDate": ISODate("2023-04-06T12:00:00Z"), "isoDayOfWeek": 4 },
{ "_id": 7, "eventDate": ISODate("2023-04-07T12:00:00Z"), "isoDayOfWeek": 5 }
]
Code examples
To view a code example for using the $isoDayOfWeek command, choose the tab for the language that you want to use: