AWS documentdb documentation change
Summary
Added new documentation page for the $setDifference operator in Amazon DocumentDB, including syntax, parameters, examples in MongoDB Shell, Node.js, and Python with connection examples
Security assessment
This change adds documentation for a new MongoDB operator ($setDifference) in Amazon DocumentDB. The documentation includes code examples that demonstrate secure connection practices using TLS (tls=true) and certificate validation (tlsCAFile=global-bundle.pem). While this promotes security best practices, there is no evidence that this change addresses a specific security vulnerability or incident. The change appears to be routine feature documentation.
Diff
diff --git a/documentdb/latest/developerguide/setDifference.md b/documentdb/latest/developerguide/setDifference.md index 8b1378917..02edc7b0e 100644 --- a//documentdb/latest/developerguide/setDifference.md +++ b//documentdb/latest/developerguide/setDifference.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#setDifference "Open PDF") @@ -1,0 +3,149 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $setDifference + +New from version 4.0. + +The `$setDifference` operator in Amazon DocumentDB is used to compare two sets and return the elements that are in the first set but not in the second set. This operator is useful for finding the unique elements between two sets. + +**Parameters** + + * `firstSet` : The first set to compare. + + * `secondSet` : The second set to compare. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$setDifference` operator to find the unique elements between two sets. + +**Create sample documents** + + + db.collection.insertMany([ + { _id: 1, fruits: ["apple", "banana", "cherry", "date"] }, + { _id: 2, fruits: ["banana", "cherry", "date", "elderberry"] } + ]); + +**Query example** + + + db.collection.aggregate([ + { + $project: { + uniqueFruits: { $setDifference: ["$fruits", ["banana", "cherry", "date"]] } + } + } + ]); + +**Output** + + + [ + { "_id": 1, "uniqueFruits": ["apple"] }, + { "_id": 2, "uniqueFruits": ["elderberry"] } + ] + +The query performs the following steps: + +1\. It uses the `$project` stage to create a new field `uniqueFruits` for each document. + +2\. The `$setDifference` operator compares the `fruits` array with the array `["banana", "cherry", "date"]` and returns the unique elements in the `fruits` array. + +## Code examples + +To view a code example for using the `$setDifference` command, choose the tab for the language that you want to use: + +Node.js + + +Here's an example of how to use the `$setDifference` operator in a Node.js application: + + + 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 collection = db.collection('mycollection'); + + // Insert sample documents + await collection.insertMany([ + { _id: 1, fruits: ["apple", "banana", "cherry", "date"] }, + { _id: 2, fruits: ["banana", "cherry", "date", "elderberry"] } + ]); + + // Query using $setDifference + const result = await collection.aggregate([ + { + $project: { + uniqueFruits: { $setDifference: ["$fruits", ["banana", "cherry", "date"]] } + } + } + ]).toArray(); + + console.log(result); + await client.close(); + } + + main(); + +Python + + +Here's an example of how to use the `$setDifference` operator in a Python application: + + + from pymongo import MongoClient + + def main(): + 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'] + + # Insert sample documents + collection.insert_many([ + {'_id': 1, 'fruits': ["apple", "banana", "cherry", "date"]}, + {'_id': 2, 'fruits': ["banana", "cherry", "date", "elderberry"]} + ]) + + # Query using $setDifference + result = list(collection.aggregate([ + { + '$project': { + 'uniqueFruits': {'$setDifference': ['$fruits', ["banana", "cherry", "date"]]} + } + } + ])) + + print(result) + client.close() + + if __name__ == '__main__': + main() + + **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) + +$set + +$setEquals + +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.