AWS documentdb documentation change
Summary
Added new documentation page for the $strLenBytes operator in Amazon DocumentDB, including parameters, MongoDB shell example, and code examples in Node.js and Python with TLS connection details.
Security assessment
This change adds routine documentation for a MongoDB operator ($strLenBytes) that calculates string length in bytes. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) for secure connections, but this is part of normal secure connection practices and not a new security feature or response to a security vulnerability. There is no evidence in the diff of addressing a specific security issue, weakness, or incident.
Diff
diff --git a/documentdb/latest/developerguide/strLenBytes.md b/documentdb/latest/developerguide/strLenBytes.md index 8b1378917..9ca286726 100644 --- a//documentdb/latest/developerguide/strLenBytes.md +++ b//documentdb/latest/developerguide/strLenBytes.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#strLenBytes "Open PDF") @@ -1,0 +3,127 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $strLenBytes + +The `$strLenBytes` operator in Amazon DocumentDB is used to determine the length of a string in bytes. This is useful when you need to understand the storage size of a string field, especially when dealing with Unicode characters that may use more than one byte per character. + +**Parameters** + + * `expression`: The string expression to calculate the length of. + + + + +## Example (MongoDB Shell) + +This example demonstrates how to use the `$strLenBytes` operator to calculate the length of string fields in bytes. + +**Create sample documents** + + + db.people.insertMany([ + { "_id": 1, "Desk": "Düsseldorf-BVV-021" }, + { "_id": 2, "Desk": "Munich-HGG-32a" }, + { "_id": 3, "Desk": "Cologne-ayu-892.50" }, + { "_id": 4, "Desk": "Dortmund-Hop-78" } + ]); + +**Query example** + + + db.people.aggregate([ + { + $project: { + "Desk": 1, + "length": { $strLenBytes: "$Desk" } + } + } + ]) + +**Output** + + + { "_id" : 1, "Desk" : "Düsseldorf-BVV-021", "length" : 19 } + { "_id" : 2, "Desk" : "Munich-HGG-32a", "length" : 14 } + { "_id" : 3, "Desk" : "Cologne-ayu-892.50", "length" : 18 } + { "_id" : 4, "Desk" : "Dortmund-Hop-78", "length" : 15 } + +Note that the length of the "Düsseldorf-BVV-021" string is 19 bytes, which is different from the number of code points (18) due to the Unicode character "Ü" occupying 2 bytes. + +## Code examples + +To view a code example for using the `$strLenBytes` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = 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'); + const db = client.db('test'); + const collection = db.collection('people'); + + const result = await collection.aggregate([ + { + $project: { + "Desk": 1, + "length": { $strLenBytes: "$Desk" } + } + } + ]).toArray(); + + console.log(result); + client.close(); + } + + example(); + +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') + db = client.test + collection = db.people + + result = list(collection.aggregate([ + { + '$project': { + "Desk": 1, + "length": { "$strLenBytes": "$Desk" } + } + } + ])) + + print(result) + 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) + +$sqrt + +$strLenCP + +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.