AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/subtract.md

Summary

Added comprehensive documentation for the $subtract operator in Amazon DocumentDB, including syntax, parameters, and code examples in MongoDB Shell, Node.js, and Python.

Security assessment

The change is a routine documentation update for a database operator with no mention of security vulnerabilities, weaknesses, or incidents. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are existing security best practices, but the documentation does not introduce new security features or address specific security issues.

Diff

diff --git a/documentdb/latest/developerguide/subtract.md b/documentdb/latest/developerguide/subtract.md
index 8b1378917..4f41aa8df 100644
--- a//documentdb/latest/developerguide/subtract.md
+++ b//documentdb/latest/developerguide/subtract.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#subtract "Open PDF")
@@ -1,0 +3,163 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $subtract
+
+The `$subtract` operator in Amazon DocumentDB is used to subtract values. It can be used to subtract dates, numbers, or a combination of both. This operator is useful for calculating the difference between two dates or subtracting a value from a number.
+
+**Parameters**
+
+  * `expression1`: The first value to be subtracted.
+
+  * `expression2`: The second value to be subtracted from `<expression1>`.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$subtract` operator to calculate the difference between two dates.
+
+**Create sample document**
+    
+    
+    db.dates.insert([
+      {
+      "_id": 1,
+      "startDate": ISODate("2023-01-01T00:00:00Z"),
+      "endDate": ISODate("2023-01-05T12:00:00Z")
+      }
+    ]);
+
+**Query example**
+    
+    
+    db.dates.aggregate([
+      {
+        $project: {
+          _id: 1,
+          durationDays: {
+            $divide: [
+              { $subtract: ["$endDate", "$startDate"] },
+              1000 * 60 * 60 * 24  // milliseconds in a day
+            ]
+          }
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    [ { _id: 1, durationDays: 4.5 } ]
+
+In this example, the `$subtract` operator is used to calculate the difference between the `$endDate` and `$startDate` in days.
+
+## Code examples
+
+To view a code example for using the `$subtract` 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');
+    
+      try {
+        await client.connect();
+        const db = client.db('test');
+        const collection = db.collection('dates');
+    
+        const pipeline = [
+          {
+            $project: {
+              _id: 1,
+              durationDays: {
+                $divide: [
+                  { $subtract: ["$endDate", "$startDate"] },
+                  1000 * 60 * 60 * 24  // Convert milliseconds to days
+                ]
+              }
+            }
+          }
+        ];
+    
+        const results = await collection.aggregate(pipeline).toArray();
+    
+        console.dir(results, { depth: null });
+    
+      } finally {
+        await client.close();
+      }
+    }
+    
+    example().catch(console.error);
+    
+
+Python
+    
+    
+    
+    from datetime import datetime, timedelta
+    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')
+    
+        try:
+            db = client.test
+            collection = db.dates
+    
+            pipeline = [
+                {
+                    "$project": {
+                        "_id": 1,
+                        "durationDays": {
+                            "$divide": [
+                                { "$subtract": ["$endDate", "$startDate"] },
+                                1000 * 60 * 60 * 24  # Convert milliseconds to days
+                            ]
+                        }
+                    }
+                }
+            ]
+    
+            results = collection.aggregate(pipeline)
+    
+            for doc in results:
+                print(doc)
+    
+        except Exception as e:
+            print(f"An error occurred: {e}")
+    
+        finally:
+            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)
+
+$substrCP
+
+$sum
+
+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.