AWS documentdb documentation change
Summary
Added new documentation page for the $setIsSubset operator in Amazon DocumentDB, including description, parameters, MongoDB Shell example, and code examples in Node.js and Python
Security assessment
This change adds documentation for a new DocumentDB operator ($setIsSubset) with code examples that include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem). While the primary focus is on documenting a query operator, the code examples demonstrate secure connection practices by including TLS configuration, which is a security best practice for database connections.
Diff
diff --git a/documentdb/latest/developerguide/setIsSubset.md b/documentdb/latest/developerguide/setIsSubset.md index 8b1378917..2054e9040 100644 --- a//documentdb/latest/developerguide/setIsSubset.md +++ b//documentdb/latest/developerguide/setIsSubset.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#setIsSubset "Open PDF") @@ -1,0 +3,117 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $setIsSubset + +The `$setIsSubset` operator in Amazon DocumentDB is used to determine if a set of values is a subset of another set. It is useful for performing set-based comparisons and operations on array fields. + +**Parameters** + + * `field`: The field to apply the `$setIsSubset` operator to. + + * `set`: The set to compare the field against. + + + + +## Example (MongoDB Shell) + +The following example demonstrates the usage of the `$setIsSubset` operator to check if the `tags` field is a subset of the specified set. + +**Create sample documents** + + + db.products.insertMany([ + { _id: 1, name: "Product A", tags: ["tag1", "tag2", "tag3"] }, + { _id: 2, name: "Product B", tags: ["tag1", "tag2"] }, + { _id: 3, name: "Product C", tags: ["tag2", "tag3"] } + ]); + +**Query example** + + + db.products.find({ + $expr: { $setIsSubset: [["tag1", "tag2"], "$tags"] } + }) + +*Note:* `$setIsSubset` is an aggregation operator and cannot be used directly in find() queries. In this example, `$expr` is used with `find()` to bridge the gap between query operators and aggregation expressions. + +**Output** + + + [ + { "_id" : 1, "name" : "Product A", "tags" : [ "tag1", "tag2", "tag3" ] }, + { "_id" : 2, "name" : "Product B", "tags" : [ "tag1", "tag2" ] } + ] + +The query returns the documents where the `tags` field is a subset of the set `["tag1", "tag2"]`. + +## Code examples + +To view a code example for using the `$setIsSubset` 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'); + + const result = await collection.find({ + $expr: { $setIsSubset: [["tag1", "tag2"], "$tags"] } + }).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'] + collection = db['products'] + + result = list(collection.find({ + '$expr': {'$setIsSubset': [['tag1', 'tag2'], '$tags']} + })) + + 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) + +$setIntersection + +$setUnion + +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.