AWS documentdb documentation change
Summary
Added comprehensive documentation for the $dateToString aggregation operator in Amazon DocumentDB, including parameters, examples in MongoDB Shell, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a date formatting operator with no mention of security vulnerabilities, patches, or security-related features. The examples show standard database operations without security context. The code examples include TLS connection parameters (tls=true, tlsCAFile) which are standard secure connection practices, not new security documentation.
Diff
diff --git a/documentdb/latest/developerguide/dateToString.md b/documentdb/latest/developerguide/dateToString.md index 8b1378917..b38236aaf 100644 --- a//documentdb/latest/developerguide/dateToString.md +++ b//documentdb/latest/developerguide/dateToString.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#dateToString "Open PDF") @@ -1,0 +3,175 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $dateToString + +The `$dateToString` aggregation operator in Amazon DocumentDB is used to convert a date or timestamp value to a string representation. This is useful when you need to format the date and time in a specific way for display or further processing. + +**Parameters** + + * `date`: The date or timestamp value to be converted to a string. + + * `format`: A string that specifies the format in which the date should be represented. The format string can include various format specifiers, such as `%Y` for the four-digit year, `%m` for the two-digit month, `%d` for the two-digit day of the month, etc. + + * `timezone`: (optional) The time zone to use for the conversion. If not specified, the time zone of the server hosting the Amazon DocumentDB cluster is used. + + * `onNull`: (optional) The value to be returned if the `date` parameter is `null`. + + + + +## Example (MongoDB Shell) + +The following example demonstrates the usage of the `$dateToString` operator to format the `logDate` field of the `missionLog` collection. + +**Create sample documents** + + + db.missionLog.insertMany([ + { _id: 1, "event":"missionStart", logDate: new Date("2020-03-15T13:41:33Z") }, + { _id: 2, "event":"jumpPoint1", logDate: new Date("2020-03-15T13:45:34Z") }, + { _id: 3, "event":"jumpPoint2", logDate: new Date("2020-03-15T13:48:21Z") }, + { _id: 4, "event":"jumpPoint3", logDate: new Date("2020-03-15T13:52:09Z") }, + { _id: 5, "event":"missionEnd", logDate: new Date("2020-03-15T13:58:44Z") } + ]); + +**Query example** + + + db.missionLog.aggregate([ + { + $project: { + event: "$event", + logDateFormatted: { + $dateToString: { + format: "%Y-%m-%d %H:%M:%S", + date: "$logDate" + } + } + } + } + ]) + +**Output** + + + [ + { + "_id": 1, + "event": "missionStart", + "logDateFormatted": "2020-03-15 13:41:33" + }, + { + "_id": 2, + "event": "jumpPoint1", + "logDateFormatted": "2020-03-15 13:45:34" + }, + { + "_id": 3, + "event": "jumpPoint2", + "logDateFormatted": "2020-03-15 13:48:21" + }, + { + "_id": 4, + "event": "jumpPoint3", + "logDateFormatted": "2020-03-15 13:52:09" + }, + { + "_id": 5, + "event": "missionEnd", + "logDateFormatted": "2020-03-15 13:58:44" + } + ] + +## Code examples + +To view a code example for using the `$dateToString` command, choose the tab for the language that you want to use: + +Node.js + + +Here's an example of using the `$dateToString` operator in a Node.js application: + + + 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 collection = db.collection('missionLog'); + + const result = await collection.aggregate([ + { + $project: { + event: "$event", + logDateFormatted: { + $dateToString: { + format: "%Y-%m-%d %H:%M:%S", + date: "$logDate" + } + } + } + } + ]).toArray(); + + console.log(result); + await client.close(); + } + + example(); + +Python + + +Here's an example of using the `$dateToString` operator in a Python application: + + + 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'] + collection = db['missionLog'] + + pipeline = [ + { + '$project': { + 'event': '$event', + 'logDateFormatted': { + '$dateToString': { + 'format': '%Y-%m-%d %H:%M:%S', + 'date': '$logDate' + } + } + } + } + ] + + result = list(collection.aggregate(pipeline)) + 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) + +$dateSubtract + +$dateTrunc + +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.