$isoDayOfWeek - Amazon DocumentDB
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

$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:

Node.js
const { MongoClient } = require('mongodb'); async function example() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const events = db.collection('events'); const result = await events.aggregate([ { $project: { _id: 1, eventDate: 1, isoDayOfWeek: { $isoDayOfWeek: '$eventDate' } } } ]).toArray(); console.log(result); client.close(); } example();
Python
from pymongo import MongoClient def example(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client.test events = db.events result = list(events.aggregate([ { '$project': { '_id': 1, 'eventDate': 1, 'isoDayOfWeek': { '$isoDayOfWeek': '$eventDate' } } } ])) print(result) client.close() example()