AWS documentdb documentation change
Summary
Added comprehensive documentation for the $expr operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a query operator ($expr) without any mention of security vulnerabilities, fixes, or security-related features. The examples show basic query functionality comparing manufacturingCost and price fields. The connection strings in code examples include standard TLS parameters but this is routine security documentation, not addressing a specific security issue.
Diff
diff --git a/documentdb/latest/developerguide/expr.md b/documentdb/latest/developerguide/expr.md index 8b1378917..8de291297 100644 --- a//documentdb/latest/developerguide/expr.md +++ b//documentdb/latest/developerguide/expr.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#expr "Open PDF") @@ -1,0 +3,117 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $expr + +New from version 4.0. + +Not supported by Elastic cluster. + +The `$expr` operator in Amazon DocumentDB allows you to use aggregation expressions within the query language. It enables you to perform complex comparisons and computations on fields within a document, similar to the way you would use aggregation pipeline stages. + +**Parameters** + + * `expression`: An expression that returns a boolean value, allowing you to perform comparisons and computations on document fields. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$expr` operator to find all documents where the `manufacturingCost` field is greater than the `price` field. + +**Create sample documents** + + + db.inventory.insertMany([ + { item: "abc", manufacturingCost: 500, price: 100 }, + { item: "def", manufacturingCost: 300, price: 450 }, + { item: "ghi", manufacturingCost: 400, price: 120 } + ]); + +**Query example** + + + db.inventory.find({ + $expr: { + $gt: ["$manufacturingCost", "$price"] + } + }) + +**Output** + + + { "_id" : ObjectId("60b9d4d68d2cac581bc5a89a"), "item" : "abc", "manufacturingCost" : 500, "price" : 100 }, + { "_id" : ObjectId("60b9d4d68d2cac581bc5a89c"), "item" : "ghi", "manufacturingCost" : 400, "price" : 120 } + +## Code examples + +To view a code example for using the `$expr` 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('inventory'); + + const result = await collection.find({ + $expr: { + $gt: ['$manufacturingCost', '$price'] + } + }).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['inventory'] + + result = list(collection.find({ + '$expr': { + '$gt': ['$manufacturingCost', '$price'] + } + })) + + 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) + +$exists + +$gt + +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.