AWS Security ChangesHomeSearch

AWS documentdb documentation change

Service: documentdb · 2026-03-31 · Documentation low

File: documentdb/latest/developerguide/dateFromString.md

Summary

Added new documentation page for the $dateFromString aggregation operator with parameters, examples in MongoDB Shell, Node.js, and Python, and a PDF link.

Security assessment

This change adds general documentation for a date conversion operator. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are routine security best practices for DocumentDB connections, but there is no evidence this addresses a specific security vulnerability, weakness, or incident. The change appears to be routine feature documentation.

Diff

diff --git a/documentdb/latest/developerguide/dateFromString.md b/documentdb/latest/developerguide/dateFromString.md
index 8b1378917..190efca69 100644
--- a//documentdb/latest/developerguide/dateFromString.md
+++ b//documentdb/latest/developerguide/dateFromString.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#dateFromString "Open PDF")
@@ -1,0 +3,169 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $dateFromString
+
+The `$dateFromString` aggregation operator in Amazon DocumentDB allows you to convert a date-time string into a date object. This is useful when your data is stored as strings but you need to perform date-based operations on the data.
+
+**Parameters**
+
+  * `dateString`: A string that represents a date and time.
+
+  * `format`: (optional) A string that specifies the format of the `dateString`. If not provided, Amazon DocumentDB will attempt to parse the string in the ISO-8601 format.
+
+  * `timezone`: (optional) A string that specifies the time zone. If not provided, Amazon DocumentDB will use the time zone of the server.
+
+  * `onError`: (optional) Specifies the action to take if the conversion fails. Possible values are `'error'` (the default, which throws an error), `'null'` (returns `null`), or `'replace'` (replaces the value with the replacement string specified in the `onErrorMessage` option).
+
+  * `onErrorMessage`: (optional) If `onError` is set to `'replace'`, this option specifies the replacement string.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use `$dateFromString` to convert a date string to a date object in Amazon DocumentDB.
+
+**Create sample documents**
+    
+    
+    db.missionLog.insertMany([
+    { _id: 1, event: "missionStart", logDate: "2020-03-15T13:41:33"},
+    { _id: 2, event: "jumpPoint1", logDate: "2020-03-15T13:45:34"},
+    { _id: 3, event: "jumpPoint2", logDate: "2020-03-15T13:48:21"},
+    { _id: 4, event: "jumpPoint3", logDate: "2020-03-15T13:52:09"},
+    { _id: 5, event: "missionEnd", logDate: "2020-03-15T13:58:44"}
+    ]);
+
+**Query example**
+    
+    
+    db.missionLog.aggregate([
+      {
+        $project: {
+          event: '$event',
+          logDate: {
+            $dateFromString: {
+              dateString: '$logDate'
+            }
+          }
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    [
+      {
+        "_id": 1,
+        "event": "missionStart",
+        "logDate": ISODate("2020-03-15T13:41:33Z")
+      },
+      {
+        "_id": 2,
+        "event": "jumpPoint1",
+        "logDate": ISODate("2020-03-15T13:45:34Z")
+      },
+      {
+        "_id": 3,
+        "event": "jumpPoint2",
+        "logDate": ISODate("2020-03-15T13:48:21Z")
+      },
+      {
+        "_id": 4,
+        "event": "jumpPoint3",
+        "logDate": ISODate("2020-03-15T13:52:09Z")
+      },
+      {
+        "_id": 5,
+        "event": "missionEnd",
+        "logDate": ISODate("2020-03-15T13:58:44Z")
+      }
+    ]
+
+## Code examples
+
+To view a code example for using the `$dateFromString` 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('missionLog');
+    
+      const result = await collection.aggregate([
+        {
+          $project: {
+            event: '$event',
+            logDate: {
+              $dateFromString: {
+                dateString: '$logDate'
+              }
+            }
+          }
+        }
+      ]).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['test']
+        collection = db['missionLog']
+    
+        result = list(collection.aggregate([
+            {
+                '$project': {
+                    'event': '$event',
+                    'logDate': {
+                        '$dateFromString': {
+                            'dateString': '$logDate'
+                        }
+                    }
+                }
+            }
+        ]))
+    
+        print(result)
+        client.close()
+    
+    example()
+
+![Warning](https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png) **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)
+
+$dateDiff
+
+$dateSubtract
+
+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.