AWS documentdb documentation change
Summary
Added comprehensive documentation for the $and aggregation operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell example, and code examples in Node.js and Python with connection strings
Security assessment
This change adds standard documentation for a database aggregation operator ($and) with example code. The connection strings in the examples include TLS parameters (tls=true, tlsCAFile=global-bundle.pem) which are security best practices for encrypted connections, but this is standard configuration documentation rather than addressing a specific security issue or vulnerability. The change appears to be routine documentation enhancement for a database feature.
Diff
diff --git a/documentdb/latest/developerguide/and-aggregation.md b/documentdb/latest/developerguide/and-aggregation.md index 8b1378917..a5cef9859 100644 --- a//documentdb/latest/developerguide/and-aggregation.md +++ b//documentdb/latest/developerguide/and-aggregation.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#and-aggregation "Open PDF") @@ -1,0 +3,146 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $and + +The `$and` aggregation operator evaluates multiple expressions and returns `true` only if all expressions evaluate to `true`. If any expression is `false`, it returns `false`. + +**Parameters** + + * `expressions`: An array of expressions to evaluate. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$and` operator to check if products meet multiple criteria. + +**Create sample documents** + + + db.products.insertMany([ + { _id: 1, name: "Laptop", price: 1200, inStock: true }, + { _id: 2, name: "Mouse", price: 25, inStock: false }, + { _id: 3, name: "Keyboard", price: 75, inStock: true } + ]); + +**Query example** + + + db.products.aggregate([ + { + $project: { + name: 1, + price: 1, + inStock: 1, + affordable: { + $and: [ + { $lt: ["$price", 100] }, + { $eq: ["$inStock", true] } + ] + } + } + } + ]); + +**Output** + + + [ + { _id: 1, name: 'Laptop', price: 1200, inStock: true, affordable: false }, + { _id: 2, name: 'Mouse', price: 25, inStock: false, affordable: false }, + { _id: 3, name: 'Keyboard', price: 75, inStock: true, affordable: true } + ] + +## Code examples + +To view a code example for using the `$and` 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('products'); + + const result = await collection.aggregate([ + { + $project: { + name: 1, + price: 1, + inStock: 1, + affordable: { + $and: [ + { $lt: ["$price", 100] }, + { $eq: ["$inStock", true] } + ] + } + } + } + ]).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.aggregate([ + { + '$project': { + 'name': 1, + 'price': 1, + 'inStock': 1, + 'affordable': { + '$and': [ + { '$lt': ['$price', 100] }, + { '$eq': ['$inStock', True] } + ] + } + } + } + ])) + + 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) + +$allElementsTrue + +$anyElementTrue + +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.