AWS documentdb documentation change
Summary
Added new documentation page for the $[] all positional operator in Amazon DocumentDB, including parameters, MongoDB shell example, and code examples in Node.js and Python
Security assessment
This is a routine documentation addition for a MongoDB operator feature. The change documents how to use the $[] operator for updating all elements in an array. The code examples include standard TLS connection parameters for secure DocumentDB connections, but this is normal documentation practice and not evidence of addressing a specific security issue. No security vulnerabilities, incidents, or weaknesses are referenced in the content.
Diff
diff --git a/documentdb/latest/developerguide/dollarBrackets-update.md b/documentdb/latest/developerguide/dollarBrackets-update.md index 8b1378917..0ed1fc78a 100644 --- a//documentdb/latest/developerguide/dollarBrackets-update.md +++ b//documentdb/latest/developerguide/dollarBrackets-update.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#dollarBrackets-update "Open PDF") @@ -1,0 +3,117 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $[] + +The `$[]` all positional operator updates all elements in an array. It is used when you need to modify every element in an array field. + +**Parameters** + + * `field.$[]`: The array field with the all positional operator to update all elements. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$[]` operator to update all array elements. + +**Create sample documents** + + + db.products.insertOne({ + _id: 1, + name: "Laptop", + prices: [1000, 1100, 1200] + }); + +**Query example** + + + db.products.updateOne( + { _id: 1 }, + { $inc: { "prices.$[]": 50 } } + ); + +**Output** + + + { + "_id" : 1, + "name" : "Laptop", + "prices" : [ 1050, 1150, 1250 ] + } + +## Code examples + +To view a code example for using the `$[]` operator, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function updateDocument() { + 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'); + + await collection.updateOne( + { _id: 1 }, + { $inc: { "prices.$[]": 50 } } + ); + + const updatedDocument = await collection.findOne({ _id: 1 }); + console.log(updatedDocument); + + await client.close(); + } + + updateDocument(); + +Python + + + + from pymongo import MongoClient + + def update_document(): + 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 + + collection.update_one( + {'_id': 1}, + {'$inc': {'prices.$[]': 50}} + ) + + updated_document = collection.find_one({'_id': 1}) + print(updated_document) + + client.close() + + update_document() + + **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) + +$ + +$[<identifier>] + +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.