AWS documentdb documentation change
Summary
Added new documentation page for the $rtrim operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds documentation for a new string manipulation operator ($rtrim) in DocumentDB. The code examples include TLS connection parameters (tls=true, tlsCAFile) which are standard security practices for database connections, but this is not the primary focus of the documentation. There is no evidence this addresses a specific security vulnerability or incident.
Diff
diff --git a/documentdb/latest/developerguide/rtrim.md b/documentdb/latest/developerguide/rtrim.md index 8b1378917..d6dd8f7a6 100644 --- a//documentdb/latest/developerguide/rtrim.md +++ b//documentdb/latest/developerguide/rtrim.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#rtrim "Open PDF") @@ -1,0 +3,154 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $rtrim + +New from version 4.0. + +Not supported by Elastic cluster. + +The `$rtrim` operator in Amazon DocumentDB is used to remove trailing characters from a string. By default, it removes trailing whitespace characters, but you can also specify a set of characters to remove by passing the chars argument. + +**Parameters** + + * `input`: The input string from which to remove trailing whitespace characters. + + * `chars`: (optional) To remove specific characters. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$rtrim` operator to remove trailing specified characters (" *") from a string. + +**Create sample documents** + + + db.collection.insert([ + { "name": "John Doe* ", "age": 30 }, + { "name": "Jane Smith ", "age": 25 }, + { "name": "Bob Johnson", "age": 35 } + ]); + +**Query example** + + + db.collection.aggregate([ + { + $project: { + _id: 0, + name: { $rtrim: { input: "$name", chars: " *" } }, + age: 1 + } + } + ]); + +**Output** + + + [ + { age: 30, name: 'John Doe' }, + { age: 25, name: 'Jane Smith' }, + { age: 35, name: 'Bob Johnson' } + ] + +## Code examples + +To view a code example for using the `$rtrim` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient, Bson } = 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'); + + try { + + const db = client.db('test'); + const collection = db.collection('collection'); + + const pipeline = [ + { + $project: { + _id: 0, + name: { $rtrim: { input: "$name", chars: " *" } }, + age: 1 + } + } + ]; + + const results = await collection.aggregate(pipeline).toArray(); + console.dir(results, { depth: null }); + + } catch (err) { + console.error('Error occurred:', err); + } finally { + await client.close(); + } + } + + example().catch(console.error); + +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') + + try: + + db = client.test + collection = db.collection + + pipeline = [ + { + "$project": { + "_id": 0, + "name": { "$rtrim": { "input": "$name", "chars": " *" } }, + "age": 1 + } + } + ] + + results = collection.aggregate(pipeline) + + for doc in results: + print(doc) + + except Exception as e: + print(f"An error occurred: {e}") + + finally: + 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) + +$reverseArray + +$sample + +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.