AWS documentdb documentation change
Summary
Added new documentation page for the $toDate aggregation operator in Amazon DocumentDB, including syntax, parameters, examples in MongoDB Shell, Node.js, and Python with connection strings
Security assessment
This change adds documentation for a new aggregation operator ($toDate) in DocumentDB version 4.0. The documentation includes standard usage examples and connection strings that contain TLS parameters (tls=true, tlsCAFile=global-bundle.pem). While TLS is a security feature, this documentation is primarily about the $toDate operator functionality, not specifically about security. The TLS parameters appear to be standard connection string examples rather than new security guidance.
Diff
diff --git a/documentdb/latest/developerguide/toDate.md b/documentdb/latest/developerguide/toDate.md index 8b1378917..10ec240e9 100644 --- a//documentdb/latest/developerguide/toDate.md +++ b//documentdb/latest/developerguide/toDate.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#toDate "Open PDF") @@ -1,0 +3,143 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $toDate + +New from version 4.0 + +The `$toDate` aggregation operator in Amazon DocumentDB is used to convert a date or date and time string to a BSON Date type. This is the inverse operation of the `$dateToString` operator. + +**Parameters** + + * `dateString`: A string representation of a date or date and time to be converted to a BSON Date type. + + * `format`: (optional) A string that specifies the format of the `dateString`. If not provided, the operator will attempt to parse the `dateString` in various standard date and time formats. + + * `timezone`: (optional) A string representing the time zone to use for the conversion. If not provided, the local time zone is used. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$toDate` operator to convert a date string to a BSON Date type. + +**Create sample documents** + + + db.events.insertMany([ + { _id: 1, eventName: "Mission Start", eventTime: "2023-04-15T10:30:00Z" }, + { _id: 2, eventName: "Checkpoint Reached", eventTime: "2023-04-15T11:15:00Z" }, + { _id: 3, eventName: "Mission End", eventTime: "2023-04-15T12:00:00Z" } + ]); + +**Query example** + + + db.events.aggregate([ + { + $project: { + eventName: 1, + eventTimeDate: { $toDate: "$eventTime" } + } + } + ]); + +**Output** + + + [ + { + "_id": 1, + "eventName": "Mission Start", + "eventTimeDate": ISODate("2023-04-15T10:30:00Z") + }, + { + "_id": 2, + "eventName": "Checkpoint Reached", + "eventTimeDate": ISODate("2023-04-15T11:15:00Z") + }, + { + "_id": 3, + "eventName": "Mission End", + "eventTimeDate": ISODate("2023-04-15T12:00:00Z") + } + ] + +## Code examples + +To view a code example for using the `$toDate` 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 collection = db.collection('events'); + + const result = await collection.aggregate([ + { + $project: { + eventName: 1, + eventTimeDate: { $toDate: '$eventTime' } + } + } + ]).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'] + collection = db['events'] + + result = list(collection.aggregate([ + { + '$project': { + 'eventName': 1, + 'eventTimeDate': { '$toDate': '$eventTime' } + } + } + ])) + + 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) + +$toBool + +$toDecimal + +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.