AWS documentdb documentation change
Summary
Added new documentation page for the $each operator with examples in MongoDB Shell, Node.js, and Python
Security assessment
This change adds documentation for the $each MongoDB operator used with $push and $addToSet. The documentation includes standard code examples with TLS connection parameters, but there is no evidence this addresses a specific security issue or vulnerability. This appears to be routine feature documentation for array operations in DocumentDB.
Diff
diff --git a/documentdb/latest/developerguide/each.md b/documentdb/latest/developerguide/each.md index 8b1378917..c43d8dba1 100644 --- a//documentdb/latest/developerguide/each.md +++ b//documentdb/latest/developerguide/each.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#each "Open PDF") @@ -1,0 +3,114 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $each + +The `$each` operator is used in conjunction with other update operators, such as `$push` and `$addToSet`, to add multiple values to an array field. It allows adding multiple elements to an array in a single operation, rather than having to execute multiple update operations. + +**Parameters** + + * `value`: The array of values to add to the array field. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$each` operator with the `$push` operator to add multiple elements to an array field. + +**Create sample documents** + + + db.fruits.insertOne({ + _id: 1, + fruits: ["apple", "banana"] + }) + +**Query example** + + + db.fruits.updateOne( + { _id: 1 }, + { $push: { fruits: { $each: ["cherry", "durian", "elderberry"] } } } + ) + +**View updated document** + + + db.fruits.findOne({ _id: 1 }) + +**Output** + + + { + _id: 1, + fruits: [ 'apple', 'banana', 'cherry', 'durian', 'elderberry' ] + } + +## Code examples + +To view a code example for using the `$each` 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('fruits'); + + await collection.updateOne( + { _id: 1 }, + { $push: { fruits: { $each: ["cherry", "durian", "elderberry"] } } } + ); + + 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['fruits'] + + collection.update_one( + {'_id': 1}, + {'$push': {'fruits': {'$each': ['cherry', 'durian', 'elderberry']}}} + ) + + 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) + +$currentDate + +$inc + +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.