AWS documentdb documentation change
Summary
Added comprehensive documentation for the $set operator in Amazon DocumentDB, including description, parameters, MongoDB Shell example, and code examples in Node.js and Python with TLS connection details.
Security assessment
The change adds documentation for a database update operator and includes code examples that demonstrate secure connection practices using TLS (tls=true and tlsCAFile=global-bundle.pem). While this promotes security best practices, there is no evidence in the diff that this change addresses a specific security vulnerability, weakness, or incident.
Diff
diff --git a/documentdb/latest/developerguide/set-update.md b/documentdb/latest/developerguide/set-update.md index 8b1378917..38dc6ab16 100644 --- a//documentdb/latest/developerguide/set-update.md +++ b//documentdb/latest/developerguide/set-update.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#set-update "Open PDF") @@ -1,0 +3,135 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $set + +The `$set` operator in Amazon DocumentDB is used to update the value of a specified field in a document. This operator allows you to add new fields or modify existing ones within a document. It is a fundamental update operator in the MongoDB Java driver, which is compatible with Amazon DocumentDB. + +**Parameters** + + * `field`: The field to update. + + * `value`: The new value for the field. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$set` operator to update the `Item` field in a document. + +**Create sample documents** + + + db.example.insert([ + { + "Item": "Pen", + "Colors": ["Red", "Green", "Blue", "Black"], + "Inventory": { + "OnHand": 244, + "MinOnHand": 72 + } + }, + { + "Item": "Poster Paint", + "Colors": ["Red", "Green", "Blue", "White"], + "Inventory": { + "OnHand": 120, + "MinOnHand": 36 + } + } + ]) + +**Query example** + + + db.example.update( + { "Item": "Pen" }, + { $set: { "Item": "Gel Pen" } } + ) + +**Output** + + + { + "Item": "Gel Pen", + "Colors": ["Red", "Green", "Blue", "Black"], + "Inventory": { + "OnHand": 244, + "MinOnHand": 72 + } + } + +## Code examples + +To view a code example for using the `$set` command, 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('example'); + + await collection.updateOne( + { "Item": "Pen" }, + { $set: { "Item": "Gel Pen" } } + ); + + const updatedDocument = await collection.findOne({ "Item": "Gel Pen" }); + 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.example + + collection.update_one( + {"Item": "Pen"}, + {"$set": {"Item": "Gel Pen"}} + ) + + updated_document = collection.find_one({"Item": "Gel Pen"}) + 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) + +$rename + +$setOnInsert + +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.