AWS documentdb documentation change
Summary
Added comprehensive documentation for the $mul operator in Amazon DocumentDB, including usage examples, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a database operator ($mul) used for multiplying field values. The documentation includes connection examples with TLS parameters (tls=true, tlsCAFile) which are standard security practices for database connections, but this is not introducing new security features or addressing specific security vulnerabilities. The change appears to be routine documentation addition for a database feature.
Diff
diff --git a/documentdb/latest/developerguide/mul.md b/documentdb/latest/developerguide/mul.md index 8b1378917..dfef0639b 100644 --- a//documentdb/latest/developerguide/mul.md +++ b//documentdb/latest/developerguide/mul.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#mul "Open PDF") @@ -1,0 +3,122 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $mul + +The `$mul` operator in Amazon DocumentDB is used to multiply the value of a field by a specified number. This can be useful for updating multiple documents atomically and consistently, such as updating flight miles based on a credit card status. + +**Parameters** + + * `field`: The field to be multiplied. + + * `multiplier`: The number to multiply the field value by. + + + + +## Example (MongoDB Shell) + +This example demonstrates how to use the `$mul` operator to double the `flight_miles` value for all documents where the `credit_card` field is `true`. + +**Create sample documents** + + + db.miles.insertMany([ + { "_id": 1, "member_since": new Date("1987-01-01"), "credit_card": false, "flight_miles": [1205, 2560, 880] }, + { "_id": 2, "member_since": new Date("1982-01-01"), "credit_card": true, "flight_miles": [2410, 5120, 1780, 5560] }, + { "_id": 3, "member_since": new Date("1999-01-01"), "credit_card": true, "flight_miles": [2410, 1760] } + ]); + +**Query example** + + + db.miles.update( + { "credit_card": { "$eq": true } }, + { "$mul": { "flight_miles.$[]": NumberInt(2) } }, + { "multi": true } + ); + +**Output** + + + { "_id" : 1, "member_since" : ISODate("1987-01-01T00:00:00Z"), "credit_card" : false, "flight_miles" : [ 1205, 2560, 880 ] } + { "_id" : 2, "member_since" : ISODate("1982-01-01T00:00:00Z"), "credit_card" : true, "flight_miles" : [ 4820, 10240, 3560, 11120 ] } + { "_id" : 3, "member_since" : ISODate("1999-01-01T00:00:00Z"), "credit_card" : true, "flight_miles" : [ 4820, 3520 ] } + +For the customers that have a credit card, their flight miles have been doubled. + +The `$[]` positional array operator is used to apply the `$mul` operation to each element in the `flight_miles` array. + +## Code examples + +To view a code example for using the `$mul` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function updateFlightMiles() { + 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('miles'); + + await collection.updateMany( + { credit_card: true }, + { $mul: { 'flight_miles.$[]': 2 } } + ); + + const documents = await collection.find().toArray(); + console.log(documents); + + await client.close(); + } + + updateFlightMiles(); + +Python + + + + from pymongo import MongoClient + + def update_flight_miles(): + 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.miles + + collection.update_many( + {'credit_card': True}, + {'$mul': {'flight_miles.$[]': 2}} + ) + + documents = list(collection.find()) + print(documents) + + client.close() + + update_flight_miles() + + **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) + +$min + +$pop + +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.