AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/let.md

Summary

Added comprehensive documentation for the $let operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell example, and code examples in Node.js and Python with connection strings.

Security assessment

This change adds standard documentation for a MongoDB aggregation operator ($let) with example usage. The code examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not introducing new security documentation - it's just showing standard secure connection patterns that were likely already documented elsewhere. There is no evidence of addressing a specific security vulnerability or incident.

Diff

diff --git a/documentdb/latest/developerguide/let.md b/documentdb/latest/developerguide/let.md
index 8b1378917..e926b6bac 100644
--- a//documentdb/latest/developerguide/let.md
+++ b//documentdb/latest/developerguide/let.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#let "Open PDF")
@@ -1,0 +3,169 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $let
+
+The `$let` operator in Amazon DocumentDB is used to bind variables to values and use those variables in the expression. It allows you to define local variables that can be used in subsequent expressions within the same stage of the aggregation pipeline.
+
+**Parameters**
+
+  * `vars`: An object that defines the variables to be used in the expression.
+
+  * `in`: The expression in which the variables defined in the vars parameter are used.
+
+
+
+
+## Example (MongoDB Shell)
+
+This example demonstrates the usage of the `$let` operator to calculate the area of a rectangle.
+
+**Create sample documents**
+    
+    
+    db.shapes.insertMany([
+      { name: "Rectangle 1", length: 5, width: 3 },
+      { name: "Rectangle 2", length: 7, width: 4 },
+      { name: "Rectangle 3", length: 6, width: 2 }
+    ]);
+
+**Query example**
+    
+    
+    db.shapes.aggregate([
+      {
+        $project: {
+          name: 1,
+          area: {
+            $let: {
+              vars: {
+                length: "$length",
+                width: "$width"
+              },
+              in: {
+                $multiply: ["$$length", "$$width"]
+              }
+            }
+          }
+        }
+      }
+    ])
+
+**Output**
+    
+    
+    [
+      {
+        "_id": ObjectId("6161e5b1a3eba3c7f2960d03"),
+        "name": "Rectangle 1",
+        "area": 15
+      },
+      {
+        "_id": ObjectId("6161e5b1a3eba3c7f2960d04"),
+        "name": "Rectangle 2",
+        "area": 28
+      },
+      {
+        "_id": ObjectId("6161e5b1a3eba3c7f2960d05"),
+        "name": "Rectangle 3",
+        "area": 12
+      }
+    ]
+
+## Code examples
+
+To view a code example for using the `$let` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function calculateRectangleAreas() {
+      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('shapes');
+    
+      const result = await shapes.aggregate([
+        {
+          $project: {
+            name: 1,
+            area: {
+              $let: {
+                vars: {
+                  length: '$length',
+                  width: '$width'
+                },
+                in: {
+                  $multiply: ['$$length', '$$width']
+                }
+              }
+            }
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+      client.close();
+    }
+    
+    calculateRectangleAreas();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    def calculate_rectangle_areas():
+        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.shapes
+    
+        result = list(shapes.aggregate([
+            {
+                '$project': {
+                    'name': 1,
+                    'area': {
+                        '$let': {
+                            'vars': {
+                                'length': '$length',
+                                'width': '$width'
+                            },
+                            'in': {
+                                '$multiply': ['$$length', '$$width']
+                            }
+                        }
+                    }
+                }
+            }
+        ]))
+    
+        print(result)
+        client.close()
+    
+    calculate_rectangle_areas()
+
+![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)
+
+$last
+
+$limit
+
+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.