AWS documentdb documentation change
Summary
Added new documentation page for the $dayOfMonth aggregation operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python with connection strings.
Security assessment
This change adds documentation for a date aggregation operator ($dayOfMonth) with standard usage examples. The code examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is routine documentation of existing security features rather than addressing a specific security issue. No evidence of vulnerability remediation or security incident response.
Diff
diff --git a/documentdb/latest/developerguide/dayOfMonth.md b/documentdb/latest/developerguide/dayOfMonth.md index 8b1378917..dc95d5164 100644 --- a//documentdb/latest/developerguide/dayOfMonth.md +++ b//documentdb/latest/developerguide/dayOfMonth.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#dayOfMonth "Open PDF") @@ -1,0 +3,118 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $dayOfMonth + +The `$dayOfMonth` aggregation operator in Amazon DocumentDB retrieves the day of the month (from 1 to 31) for a given date. This operator is useful for grouping, filtering, or extracting the day of the month from date fields in your documents. + +**Parameters** + + * `date expression`: The date expression can be a date field from the document, a date object, or a date string. + + + + +## Example (MongoDB Shell) + +This example demonstrates how to use the `$dayOfMonth` operator to extract the day of the month from a date field in the document. + +**Create sample documents** + + + db.events.insertMany([ + { _id: 1, eventDate: new Date("2022-01-15T12:00:00Z") }, + { _id: 2, eventDate: new Date("2022-02-28T15:30:00Z") }, + { _id: 3, eventDate: new Date("2022-03-01T09:45:00Z") }, + { _id: 4, eventDate: new Date("2022-04-30T23:59:59Z") } + ]); + +**Query example** + + + db.events.aggregate([ + { $project: { + eventDay: { $dayOfMonth: "$eventDate" } + }} + ]) + +**Output** + + + [ + { "_id" : 1, "eventDay" : 15 }, + { "_id" : 2, "eventDay" : 28 }, + { "_id" : 3, "eventDay" : 1 }, + { "_id" : 4, "eventDay" : 30 } + ] + +## Code examples + +To view a code example for using the `$dayOfMonth` 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: { + eventDay: { $dayOfMonth: "$eventDate" } + }} + ]).toArray(); + + console.log(result); + await 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.mydatabase + events = db.events + + result = list(events.aggregate([ + { "$project": { + "eventDay": { "$dayOfMonth": "$eventDate" } + }} + ])) + + print(result) + client.close() + + example() + + **Javascript is disabled or is unavailable in your browser.** + +To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions. + +[Document Conventions](/general/latest/gr/docconventions.html) + +$dateTrunc + +$dayOfWeek + +Did this page help you? - Yes + +Thanks for letting us know we're doing a good job! + +If you've got a moment, please tell us what we did right so we can do more of it. + +Did this page help you? - No + +Thanks for letting us know this page needs work. We're sorry we let you down. + +If you've got a moment, please tell us how we can make the documentation better.