AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/changeStream.md

Summary

Added comprehensive documentation for the $changeStream aggregation stage in Amazon DocumentDB, including parameters, examples in MongoDB Shell, Node.js, and Python, with connection examples using TLS

Security assessment

This change adds documentation for a new feature (change streams) but does not address any specific security vulnerability or incident. The examples include TLS connections which is standard security practice, but this is not documentation about a security feature - it's documentation about a data monitoring feature that happens to include secure connection examples. There is no evidence of security fixes or vulnerability disclosures in the diff.

Diff

diff --git a/documentdb/latest/developerguide/changeStream.md b/documentdb/latest/developerguide/changeStream.md
index 8b1378917..e55122b36 100644
--- a//documentdb/latest/developerguide/changeStream.md
+++ b//documentdb/latest/developerguide/changeStream.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#changeStream "Open PDF")
@@ -1,0 +3,141 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $changeStream
+
+Not supported by Elastic cluster.
+
+The `$changeStream` aggregation stage opens a change stream cursor to monitor real-time changes to a collection. It returns change event documents when insert, update, replace, or delete operations occur.
+
+**Parameters**
+
+  * `fullDocument`: Specifies whether to return the full document for update operations. Options are `default` or `updateLookup`.
+
+  * `resumeAfter`: Optional. Resume token to continue from a specific point in the change stream.
+
+  * `startAtOperationTime`: Optional. Timestamp to start the change stream from.
+
+  * `allChangesForCluster`: Optional. Boolean value. When `true`, watches all changes across the cluster (for admin database). When `false` (default), watches only the specified collection.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates using the `$changeStream` stage to monitor changes to a collection.
+
+**Query example**
+    
+    
+    // Open change stream first
+    const changeStream = db.inventory.aggregate([
+      { $changeStream: { fullDocument: "updateLookup" } }
+    ]);
+    
+    // In another session, insert a document
+    db.inventory.insertOne({ _id: 1, item: "Widget", qty: 10 });
+    
+    // Back in the first session, read the change event
+    if (changeStream.hasNext()) {
+      print(tojson(changeStream.next()));
+    }
+
+**Output**
+    
+    
+    {
+      _id: { _data: '...' },
+      operationType: 'insert',
+      clusterTime: Timestamp(1, 1234567890),
+      fullDocument: { _id: 1, item: 'Widget', qty: 10 },
+      ns: { db: 'test', coll: 'inventory' },
+      documentKey: { _id: 1 }
+    }
+
+## Code examples
+
+To view a code example for using the `$changeStream` aggregation stage, 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('inventory');
+    
+      // Open change stream
+      const changeStream = collection.watch([]);
+    
+      changeStream.on('change', (change) => {
+        console.log('Change detected:', change);
+      });
+    
+      // Simulate insert in another operation
+      setTimeout(async () => {
+        await collection.insertOne({ _id: 1, item: 'Widget', qty: 10 });
+      }, 1000);
+    
+      // Keep connection open to receive changes
+      // In production, handle cleanup appropriately
+    }
+    
+    example();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    import threading
+    import time
+    
+    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['inventory']
+    
+        # Open change stream
+        change_stream = collection.watch([])
+    
+        # Insert document in separate thread after delay
+        def insert_doc():
+            time.sleep(1)
+            collection.insert_one({'_id': 1, 'item': 'Widget', 'qty': 10})
+    
+        threading.Thread(target=insert_doc).start()
+    
+        # Watch for changes
+        for change in change_stream:
+            print('Change detected:', change)
+            break  # Exit after first change
+    
+        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)
+
+$ceil
+
+$cmp
+
+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.