AWS documentdb documentation change
Summary
Added new documentation page for the $setIntersection operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell example, and code examples in Node.js and Python
Security assessment
This change adds routine documentation for a database operator ($setIntersection) with standard usage examples. The code examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not the primary focus of the documentation. There is no evidence of addressing a specific security vulnerability, weakness, or incident.
Diff
diff --git a/documentdb/latest/developerguide/setIntersection.md b/documentdb/latest/developerguide/setIntersection.md index 8b1378917..015ae1a28 100644 --- a//documentdb/latest/developerguide/setIntersection.md +++ b//documentdb/latest/developerguide/setIntersection.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#setIntersection "Open PDF") @@ -1,0 +3,128 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $setIntersection + +The `$setIntersection` operator in Amazon DocumentDB is used to return the common elements between two or more arrays. This operator is particularly useful when working with sets of data, allowing you to find the intersection of multiple sets. + +**Parameters** + + * `array1`: The first array to intersect. + + * `array2`: The second array to intersect. + + * `arrayN`: (optional) Additional arrays to intersect. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$setIntersection` operator to find the common elements between two arrays. + +**Create sample documents** + + + db.collection.insertMany([ + { _id: 1, colors: ["red", "blue", "green"] }, + { _id: 2, colors: ["blue", "yellow", "orange"] }, + { _id: 3, colors: ["red", "green", "purple"] } + ]) + +**Query example** + + + db.collection.aggregate([ + { $project: { + _id: 1, + commonColors: { $setIntersection: ["$colors", ["red", "blue", "green"]] } + } + } + ]) + +**Output** + + + [ + { "_id": 1, "commonColors": ["red", "blue", "green"] }, + { "_id": 2, "commonColors": ["blue"] }, + { "_id": 3, "commonColors": ["red", "green"] } + ] + +## Code examples + +To view a code example for using the `$setIntersection` 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('mycollection'); + + const result = await collection.aggregate([ + { + $project: { + _id: 1, + commonColors: { $setIntersection: ["$colors", ["red", "blue", "green"]] } + } + } + ]).toArray(); + + console.log(result); + 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['mycollection'] + + result = list(collection.aggregate([ + { + '$project': { + '_id': 1, + 'commonColors': { '$setIntersection': ["$colors", ["red", "blue", "green"]] } + } + } + ])) + + print(result) + client.close() + + example() + + **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) + +$setEquals + +$setIsSubset + +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.