AWS documentdb documentation change
Summary
Added new documentation page for the $setUnion aggregation 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 aggregation operator ($setUnion) 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 new security documentation - it's just showing standard secure connection setup. There is no evidence this addresses a specific security vulnerability, weakness, or incident.
Diff
diff --git a/documentdb/latest/developerguide/setUnion.md b/documentdb/latest/developerguide/setUnion.md index 8b1378917..e27f1e48e 100644 --- a//documentdb/latest/developerguide/setUnion.md +++ b//documentdb/latest/developerguide/setUnion.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#setUnion "Open PDF") @@ -1,0 +3,133 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $setUnion + +The `$setUnion` aggregation operator in Amazon DocumentDB is used to combine two or more sets of values and return a set that contains all the unique elements from the input sets. This operator is useful when you need to perform set-based operations on array fields in your documents. + +**Parameters** + + * `expression1`: An expression that resolves to an array. + + * `expression2`: An expression that resolves to an array. + + * `expressionN`: Additional expressions that resolve to arrays (optional). + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$setUnion` operator to combine the unique elements from two array fields in a collection. + +**Create sample documents** + + + db.users.insertMany([ + { _id: 1, name: "Alice", hobbies: ["reading", "swimming"], skills: ["coding", "writing"] }, + { _id: 2, name: "Bob", hobbies: ["cooking", "gardening"], skills: ["coding", "photography"] }, + { _id: 3, name: "Charlie", hobbies: ["reading", "painting"], skills: ["gardening", "music"] } + ]); + +**Query example** + + + db.users.aggregate([ + { + $project: { + name: 1, + allInterests: { $setUnion: ["$hobbies", "$skills"] } + } + } + ]); + +**Output** + + + [ + { "_id" : 1, "name" : "Alice", "allInterests" : [ "coding", "reading", "swimming", "writing" ] }, + { "_id" : 2, "name" : "Bob", "allInterests" : [ "coding", "cooking", "gardening", "photography" ] }, + { "_id" : 3, "name" : "Charlie", "allInterests" : [ "gardening", "music", "painting", "reading" ] } + ] + +In this example, the `$setUnion` operator is used to combine the unique elements from the `hobbies` and `skills` array fields for each user document. The resulting `allInterests` field contains the union of all the unique hobbies and skills for each user. + +## Code examples + +To view a code example for using the `$setUnion` 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 users = db.collection('users'); + + const result = await users.aggregate([ + { + $project: { + _id: 1, + name: 1, + allInterests: { $setUnion: ["$hobbies", "$skills"] } + } + } + ]).toArray(); + + console.log(result); + 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'] + users = db['users'] + + result = list(users.aggregate([ + { + '$project': { + '_id': 1, + 'name': 1, + 'allInterests': { '$setUnion': ["$hobbies", "$skills"] } + } + } + ])) + + 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) + +$setIsSubset + +$skip + +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.