AWS documentdb documentation change
Summary
Added new documentation page for the $in aggregation operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell example, and code examples in Node.js and Python with TLS connection details
Security assessment
The change adds standard documentation for a database operator without mentioning any security vulnerabilities or incidents. However, it includes security documentation by showing TLS-enabled connection strings with tls=true and tlsCAFile parameters, which demonstrates secure connection practices for DocumentDB. The code examples explicitly use TLS for encrypted connections, which is a security best practice.
Diff
diff --git a/documentdb/latest/developerguide/in-aggregation.md b/documentdb/latest/developerguide/in-aggregation.md index 8b1378917..949b6bd1d 100644 --- a//documentdb/latest/developerguide/in-aggregation.md +++ b//documentdb/latest/developerguide/in-aggregation.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#in-aggregation "Open PDF") @@ -1,0 +3,127 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $in + +The `$in` aggregation operator checks if a specified value exists within an array. It returns `true` if the value is found in the array, and `false` otherwise. + +**Parameters** + + * `value`: The value to search for. + + * `array`: The array to search within. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$in` operator to check if a specific skill exists in each employee's skill set. + +**Create sample documents** + + + db.employees.insertMany([ + { _id: 1, name: "Sarah", skills: ["Python", "JavaScript", "SQL"] }, + { _id: 2, name: "Mike", skills: ["Java", "C++", "Go"] }, + { _id: 3, name: "Emma", skills: ["Python", "Ruby", "Rust"] } + ]); + +**Query example** + + + db.employees.aggregate([ + { + $project: { + name: 1, + hasPython: { $in: ["Python", "$skills"] } + } + } + ]); + +**Output** + + + [ + { _id: 1, name: 'Sarah', hasPython: true }, + { _id: 2, name: 'Mike', hasPython: false }, + { _id: 3, name: 'Emma', hasPython: true } + ] + +## Code examples + +To view a code example for using the `$in` aggregation operator, 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('employees'); + + const result = await collection.aggregate([ + { + $project: { + name: 1, + hasPython: { $in: ["Python", "$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'] + collection = db['employees'] + + result = list(collection.aggregate([ + { + '$project': { + 'name': 1, + 'hasPython': { '$in': ['Python', '$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) + +$ifNull + +$indexOfArray + +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.