AWS documentdb documentation change
Summary
Added new documentation page for the $elemMatch operator in Amazon DocumentDB, including overview, parameters, usage examples in MongoDB Shell, Node.js, and Python, with connection examples showing TLS configuration.
Security assessment
This change adds routine documentation for a query operator ($elemMatch) with standard usage examples. The code examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not introducing new security documentation - it's showing standard secure connection patterns that were already recommended. There is no evidence this addresses a specific security vulnerability or incident.
Diff
diff --git a/documentdb/latest/developerguide/elemMatch.md b/documentdb/latest/developerguide/elemMatch.md index 8b1378917..311f3ce90 100644 --- a//documentdb/latest/developerguide/elemMatch.md +++ b//documentdb/latest/developerguide/elemMatch.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#elemMatch "Open PDF") @@ -1,0 +3,120 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $elemMatch + +The `$elemMatch` operator in Amazon DocumentDB is used to query an array field and return documents where at least one element in the array matches the specified criteria. This operator is particularly useful when you have complex data structures with nested arrays or embedded documents. + +Planner version 2.0 added index support for `$elemMatch`. + +**Parameters** + + * `field`: The array field to query. + + * `query`: The criteria to match against the array elements. + + + + +**Using`$elemMatch` within an `$all` expression** + +See [Using $elemMatch within an $all expression](./functional-differences.html#functional-differences.elemMatch) for limitations regarding the use of the `$elemMatch` operator within an `$all` expression. + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$elemMatch` operator to find documents where the `parts` array has at least one element that matches the specified criteria. + +**Create sample documents** + + + db.col.insertMany([ + { _id: 1, parts: [{ part: "xyz", qty: 10 }, { part: "abc", qty: 20 }] }, + { _id: 2, parts: [{ part: "xyz", qty: 5 }, { part: "abc", qty: 10 }] }, + { _id: 3, parts: [{ part: "xyz", qty: 15 }, { part: "abc", qty: 100 }] }, + { _id: 4, parts: [{ part: "abc", qty: 150 }] } + ]); + +**Query example** + + + db.col.find({ + parts: { "$elemMatch": { part: "xyz", qty: { $lt: 11 } } } + }) + +**Output** + + + { "_id" : 1, "parts" : [ { "part" : "xyz", "qty" : 10 }, { "part" : "abc", "qty" : 20 } ] } + { "_id" : 2, "parts" : [ { "part" : "xyz", "qty" : 5 }, { "part" : "abc", "qty" : 10 } ] } + +## Code examples + +To view a code example for using the `$elemMatch` 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 col = db.collection('col'); + + const result = await col.find({ + parts: { + "$elemMatch": { part: "xyz", qty: { $lt: 11 } } + } + }).toArray(); + + console.log(JSON.stringify(result, null, 2)); + 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'] + col = db['col'] + + result = list(col.find({ + 'parts': { + '$elemMatch': {'part': 'xyz', 'qty': {'$lt': 11}} + } + })) + + 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) + +$comment + +$eq + +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.