AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/mod.md

Summary

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

Security assessment

This change adds standard documentation for the $mod arithmetic operator. The code examples include TLS connection parameters (tls=true, tlsCAFile) which are security best practices for encrypted connections, but these are standard connection examples rather than new security documentation. There is no evidence this addresses a specific security vulnerability or incident.

Diff

diff --git a/documentdb/latest/developerguide/mod.md b/documentdb/latest/developerguide/mod.md
index 8b1378917..440bf9ee2 100644
--- a//documentdb/latest/developerguide/mod.md
+++ b//documentdb/latest/developerguide/mod.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#mod "Open PDF")
@@ -1,0 +3,123 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $mod
+
+The `$mod` operator is an arithmetic operator that performs a modulo operation on a number. It returns the remainder of dividing one number by another. This operator is commonly used to determine if a number is odd or even, or to distribute items into a finite number of groups.
+
+**Parameters**
+
+  * `expression1`: The dividend expression.
+
+  * `expression2`: The divisor expression.
+
+
+
+
+## Example (MongoDB Shell)
+
+This example demonstrates how to use the `$mod` operator to determine the number of leftover widgets when shipping in packages of 100.
+
+**Create sample documents**
+    
+    
+    db.widgets.insertMany([
+      { "_id" : 1, "widget" : "A", "count" : 80372 },
+      { "_id" : 2, "widget" : "B", "count" : 409282 },
+      { "_id" : 3, "widget" : "C", "count" : 60739 }
+    ])
+
+**Query example**
+    
+    
+    db.widgets.aggregate([
+      { $addFields: { leftOver: { $mod: [ "$count", 100 ] } } }
+    ])
+
+**Output**
+    
+    
+    [
+      { "_id" : 1, "widget" : "A", "count" : 80372, "leftOver" : 72 },
+      { "_id" : 2, "widget" : "B", "count" : 409282, "leftOver" : 82 },
+      { "_id" : 3, "widget" : "C", "count" : 60739, "leftOver" : 39 }
+    ]
+
+The output shows the remainder of the `count` divided by 100 for each document, which represents the number of leftover widgets when shipping in packages of 100.
+
+## Code examples
+
+To view a code example for using the `$mod` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function main() {
+      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 widgets = db.collection('widgets');
+    
+      await widgets.insertMany([
+        { "_id" : 1, "widget" : "A", "count" : 80372 },
+        { "_id" : 2, "widget" : "B", "count" : 409282 },
+        { "_id" : 3, "widget" : "C", "count" : 60739 }
+      ]);
+    
+      const result = await widgets.aggregate([
+        { $addFields: { leftOver: { $mod: [ "$count", 100 ] } } }
+      ]).toArray();
+    
+      console.log(result);
+      client.close();
+    }
+    
+    main();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+    db = client['test']
+    widgets = db['widgets']
+    
+    widgets.insert_many([
+        { "_id" : 1, "widget" : "A", "count" : 80372 },
+        { "_id" : 2, "widget" : "B", "count" : 409282 },
+        { "_id" : 3, "widget" : "C", "count" : 60739 }
+    ])
+    
+    result = list(widgets.aggregate([
+        { "$addFields": { "leftOver": { "$mod": [ "$count", 100 ] } } }
+    ]))
+    
+    print(result)
+    client.close()
+
+![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)
+
+$minute
+
+$month
+
+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.