AWS documentdb documentation change
Summary
Added new documentation page for the $replaceAll operator in Amazon DocumentDB, including description, parameters, examples in MongoDB Shell, and code examples in Node.js and Python
Security assessment
This change adds documentation for a new MongoDB aggregation operator ($replaceAll) in Amazon DocumentDB. The documentation includes functional examples and code samples but contains no references to security vulnerabilities, security patches, or security features. The code examples show standard database operations without any security-specific context.
Diff
diff --git a/documentdb/latest/developerguide/replaceAll.md b/documentdb/latest/developerguide/replaceAll.md index 8b1378917..3a5301ef2 100644 --- a//documentdb/latest/developerguide/replaceAll.md +++ b//documentdb/latest/developerguide/replaceAll.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#replaceAll "Open PDF") @@ -1,0 +3,190 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $replaceAll + +Introduced in 5.0 + +The `$replaceAll` operator in Amazon DocumentDB is used to replace all occurrences of a specified string pattern within a field with a new string. This operator can be useful for tasks such as data normalization, text cleaning, and string manipulation. + +**Parameters** + + * `input`: The field or expression containing the string to be replaced. + + * `find`: The string pattern to search for and replace. + + * `replacement`: The string to replace the matched occurrences with. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$replaceAll` operator in an aggregation pipeline to replace all occurrences of the string "Chocolatier" with "Chocolate Co." in the "brandName" field of a "products" collection. + +**Create sample documents** + + + db.products.insertMany([ + { + "_id": 1, + "productId": "PROD-0Y9GL0", + "brandName": "Gordon's Chocolatier", + "category": "CPG", + "rating": { + "average": 4.8 + } + }, + { + "_id": 2, + "productId": "PROD-1X2YZ3", + "brandName": "Premium Chocolatier", + "category": "CPG", + "rating": { + "average": 4.5 + } + }, + { + "_id": 3, + "productId": "PROD-Y2E9H5", + "name": "Nutrition Co. - Original Corn Flakes Cereal", + "category": "Breakfast Cereals", + "price": 8.5 + } + ]); + +**Query example** + + + db.products.aggregate([ + { + $addFields: { + "brandName": { + $replaceAll: { + input: "$brandName", + find: "Chocolatier", + replacement: "Chocolate Co." + } + } + } + } + ]) + +**Output** + + + [ + { + _id: 1, + productId: 'PROD-0Y9GL0', + brandName: "Gordon's Chocolate Co.", + category: 'CPG', + rating: { average: 4.8 } + }, + { + _id: 2, + productId: 'PROD-1X2YZ3', + brandName: 'Premium Chocolate Co.', + category: 'CPG', + rating: { average: 4.5 } + }, + { + _id: 3, + productId: 'PROD-Y2E9H5', + name: 'Nutrition Co. - Original Corn Flakes Cereal', + category: 'Breakfast Cereals', + price: 8.5, + brandName: null + } + ] + + +## Code examples + +To view a code example for using the `$replaceAll` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function replaceAll() { + 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'); + + const results = await collection.aggregate([ + { + $addFields: { + "brandName": { + $replaceAll: { + input: "$brandName", + find: "Chocolatier", + replacement: "Chocolate Co." + } + } + } + } + ]).toArray(); + + console.log(results); + + await client.close(); + } + + replaceAll(); + +Python + + + + from pymongo import MongoClient + + def replace_all(): + 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 + + results = list(collection.aggregate([ + { + "$addFields": { + "brandName": { + "$replaceAll": { + "input": "$brandName", + "find": "Chocolatier", + "replacement": "Chocolate Co." + } + } + } + } + ])) + + print(results) + + client.close() + + replace_all() + + **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) + +$regexMatch + +$replaceOne + +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.