AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/toBool.md

Summary

Added new documentation page for the $toBool operator in Amazon DocumentDB, including syntax, parameters, examples, and code samples in Node.js and Python

Security assessment

This change adds documentation for a new MongoDB aggregation operator ($toBool) in Amazon DocumentDB. The documentation includes standard usage examples and code samples. While the code examples show TLS connection parameters (tls=true, tlsCAFile), these are standard secure connection practices already documented elsewhere and not the primary focus of this page. There is no evidence this addresses a specific security vulnerability or incident.

Diff

diff --git a/documentdb/latest/developerguide/toBool.md b/documentdb/latest/developerguide/toBool.md
index 8b1378917..e5285f6cd 100644
--- a//documentdb/latest/developerguide/toBool.md
+++ b//documentdb/latest/developerguide/toBool.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#toBool "Open PDF")
@@ -1,0 +3,135 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $toBool
+
+The `$toBool` operator in Amazon DocumentDB converts an expression to a boolean value.
+
+**Parameters**
+
+  * `expression`: The expression to be converted to a boolean value.
+
+
+
+
+**Note** : Any string converts to `true`.
+
+## Example (MongoDB Shell)
+
+The following example demonstrates using the `$toBool` operator to normalize device state values from different data types.
+
+**Create sample documents**
+    
+    
+    db.deviceStates.insertMany([
+      { _id: 1, deviceId: "sensor-001", status: true },
+      { _id: 2, deviceId: "camera-002", status: 1 },
+      { _id: 3, deviceId: "thermostat-003", status: "active" },
+      { _id: 4, deviceId: "doorlock-004", status: 0 }
+    ]);
+
+**Query example**
+    
+    
+    db.deviceStates.aggregate([
+      {
+        $project: {
+          _id: 1,
+          deviceId: 1,
+          isActive: { $toBool: "$status" }
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    [
+      { "_id": 1, "deviceId": "sensor-001", "isActive": true },
+      { "_id": 2, "deviceId": "camera-002", "isActive": true },
+      { "_id": 3, "deviceId": "thermostat-003", "isActive": true },
+      { "_id": 4, "deviceId": "doorlock-004", "isActive": false }
+    ]
+
+## Code examples
+
+To view a code example for using the `$toBool` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function main() {
+      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('deviceStates');
+    
+      const result = await collection.aggregate([
+        {
+          $project: {
+            _id: 1,
+            deviceId: 1,
+            isActive: { $toBool: '$status' }
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+    
+      await client.close();
+    }
+    
+    main();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    def main():
+        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['deviceStates']
+    
+        result = list(collection.aggregate([
+            {
+                '$project': {
+                    '_id': 1,
+                    'deviceId': 1,
+                    'isActive': { '$toBool': '$status' }
+                }
+            }
+        ]))
+    
+        print(result)
+    
+        client.close()
+    
+    if __name__ == '__main__':
+        main()
+
+![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)
+
+$switch
+
+$toDate
+
+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.