AWS Security ChangesHomeSearch

AWS documentdb documentation change

Service: documentdb · 2026-03-31 · Documentation low

File: documentdb/latest/developerguide/toString.md

Summary

Added new documentation page for the $toString operator in Amazon DocumentDB with examples in MongoDB Shell, Node.js, and Python

Security assessment

This change adds documentation for a new operator ($toString) for converting values to strings. The code examples include standard TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are routine security best practices for DocumentDB connections, but there is no evidence this addresses a specific security vulnerability or incident. The change appears to be routine feature documentation.

Diff

diff --git a/documentdb/latest/developerguide/toString.md b/documentdb/latest/developerguide/toString.md
index 8b1378917..0494127e7 100644
--- a//documentdb/latest/developerguide/toString.md
+++ b//documentdb/latest/developerguide/toString.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#toString "Open PDF")
@@ -1,0 +3,117 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $toString
+
+New from version 4.0
+
+The `$toString` operator in Amazon DocumentDB is used to convert a value of any type (except for null) to a string representation. This can be useful when you need to perform string operations on values that are not originally in string format.
+
+**Parameters**
+
+  * `expression`: The expression to convert to a string.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$toString` operator to convert numeric values to strings.
+
+**Create sample documents**
+    
+    
+    db.numbers.insertMany([
+      { "_id": 1, "value": 42 },
+      { "_id": 2, "value": 3.14 }
+    ]);
+
+**Query example**
+    
+    
+    db.numbers.aggregate([
+      { $project: {
+        _id: 1,
+        valueAsString: { $toString: "$value" }
+      }}
+    ]);
+
+**Output**
+    
+    
+    { "_id": 1, "valueAsString": "42" }
+    { "_id": 2, "valueAsString": "3.14" }
+
+## Code examples
+
+To view a code example for using the `$toString` 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('numbers');
+    
+      const result = await collection.aggregate([
+        { $project: {
+          _id: 1,
+          valueAsString: { $toString: '$value' }
+        }}
+      ]).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['numbers']
+    
+        result = list(collection.aggregate([
+            { '$project': {
+                '_id': 1,
+                'valueAsString': { '$toString': '$value' }
+            }}
+        ]))
+    
+        print(result)
+        client.close()
+    
+    example()
+
+![Warning](https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png) **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)
+
+$toObjectId
+
+$toUpper
+
+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.