AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/dateSubtract.md

Summary

Added comprehensive documentation for the $dateSubtract aggregation operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python with connection details.

Security assessment

This change adds documentation for a new aggregation operator ($dateSubtract) in DocumentDB version 5.0. The documentation includes standard code examples with TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not introducing new security features or addressing specific security vulnerabilities. The change appears to be routine feature documentation.

Diff

diff --git a/documentdb/latest/developerguide/dateSubtract.md b/documentdb/latest/developerguide/dateSubtract.md
index 8b1378917..81230aea8 100644
--- a//documentdb/latest/developerguide/dateSubtract.md
+++ b//documentdb/latest/developerguide/dateSubtract.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#dateSubtract "Open PDF")
@@ -1,0 +3,149 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $dateSubtract
+
+New from version 5.0
+
+The `$dateSubtract` aggregation operator in Amazon DocumentDB allows you to subtract a specified duration from a date value.
+
+**Parameters**
+
+  * `date`: A date expression that resolves to a date or timestamp.
+
+  * `subtrahend`: A duration expression that specifies the amount of time to subtract from the `date` expression.
+
+  * `unit`: A string that specifies the time unit for the `subtrahend` expression. Supported units are "year", "quarter", "month", "week", "day", "hour", "minute", "second", and "millisecond".
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$dateSubtract` operator to calculate the date one year ago from the current date.
+
+**Create sample documents**
+    
+    
+    db.events.insertOne({
+      eventName: "Player joined",
+      eventTime: ISODate("2023-04-01T12:00:00Z")
+    });
+
+**Query example**
+    
+    
+    db.events.aggregate([
+      {
+        $project: {
+          eventName: 1,
+          oneYearAgo: {
+            $dateSubtract: {
+              startDate: "$eventTime",
+              amount: 1,
+              unit: "year"
+            }
+          }
+        }
+      }
+    ])
+
+**Output**
+    
+    
+    {
+      "_id" : ObjectId("64567890abcdef012345678"),
+      "eventName" : "Player joined",
+      "oneYearAgo" : ISODate("2022-04-01T12:00:00Z")
+    }
+
+## Code examples
+
+To view a code example for using the `$dateSubtract` 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: {
+            eventName: 1,
+            oneYearAgo: {
+              $dateSubtract: {
+                startDate: "$eventTime",
+                amount: 1,
+                unit: "year"
+              }
+            }
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+      await client.close();
+    }
+    
+    example();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    from bson.date_time import datetime
+    
+    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': {
+                    'eventName': 1,
+                    'oneYearAgo': {
+                        '$dateSubtract': {
+                            'startDate': '$eventTime',
+                            'amount': 1,
+                            'unit': 'year'
+                        }
+                    }
+                }
+            }
+        ]))
+    
+        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)
+
+$dateFromString
+
+$dateToString
+
+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.