AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/addToSet.md

Summary

Added new documentation page for the $addToSet operator in Amazon DocumentDB, including description, parameters, MongoDB shell example, and code examples in Node.js and Python with connection strings.

Security assessment

This change adds standard documentation for a database operator ($addToSet) with example code. The connection strings in the examples include TLS parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for encrypted connections, but this is not new security documentation - it's just standard secure connection examples. There is no evidence of addressing a specific security vulnerability or incident.

Diff

diff --git a/documentdb/latest/developerguide/addToSet.md b/documentdb/latest/developerguide/addToSet.md
index 8b1378917..8cb47a405 100644
--- a//documentdb/latest/developerguide/addToSet.md
+++ b//documentdb/latest/developerguide/addToSet.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#addToSet "Open PDF")
@@ -1,0 +3,117 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $addToSet
+
+The `$addToSet` operator in Amazon DocumentDB is used to add a value to an array only if the value is not already present in the array. This is useful for ensuring that an array contains unique elements.
+
+**Parameters**
+
+  * `field`: The field to update.
+
+  * `value`: The value to add to the array field. This can be a single value or an expression.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$addToSet` operator to add unique elements to an array.
+
+**Create sample documents**
+    
+    
+    db.products.insertMany([
+      { "_id": 1, "item": "apple", "tags": ["fruit", "red", "round"] },
+      { "_id": 2, "item": "banana", "tags": ["fruit", "yellow"] },
+      { "_id": 3, "item": "cherry", "tags": ["fruit", "red"] }
+    ])
+
+**Query example**
+    
+    
+    db.products.update(
+      { "item": "apple" },
+      { $addToSet: { "tags": "green" } }
+    )
+
+**Output**
+    
+    
+    { "_id": 1, "item": "apple", "tags": ["fruit", "red", "round", "green"] }
+
+In this example, the `$addToSet` operator adds the "green" tag to the "tags" array of the document where the "item" field is "apple". Since "green" was not already in the array, it was added.
+
+## Code examples
+
+To view a code example for using the `$addToSet` 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('products');
+    
+      await collection.updateOne(
+        { "item": "apple" },
+        { $addToSet: { "tags": "green" } }
+      );
+    
+      const updatedDoc = await collection.findOne({ "item": "apple" });
+      console.log(updatedDoc);
+    
+      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.products
+    
+        collection.update_one(
+            {"item": "apple"},
+            {"$addToSet": {"tags": "green"}}
+        )
+    
+        updated_doc = collection.find_one({"item": "apple"})
+        print(updated_doc)
+    
+        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)
+
+$[<identifier>]
+
+$bit
+
+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.