AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/literal.md

Summary

Added new documentation page for the $literal operator in Amazon DocumentDB, including explanation, MongoDB shell example, and code examples in Node.js and Python

Security assessment

This change adds standard documentation for a database operator ($literal) used in aggregation pipelines. There is no mention of security vulnerabilities, patches, or security features. The examples show basic usage of the operator without any security context or implications.

Diff

diff --git a/documentdb/latest/developerguide/literal.md b/documentdb/latest/developerguide/literal.md
index 8b1378917..c1db847ab 100644
--- a//documentdb/latest/developerguide/literal.md
+++ b//documentdb/latest/developerguide/literal.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#literal "Open PDF")
@@ -1,0 +3,148 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $literal
+
+The `$literal` operator in Amazon DocumentDB is used to represent a literal value within an aggregation pipeline stage. It allows you to include a specific value, such as a number, string, or boolean, without interpreting it as a field reference or expression.
+
+This operator is particularly useful when you need to include a literal value as part of a more complex aggregation pipeline, such as when building dynamic query filters or performing calculations.
+
+**Parameters**
+
+None
+
+## Example (MongoDB Shell)
+
+The following example demonstrates the use of the `$literal` operator to include a literal value in an aggregation pipeline. The `$literal` operator is used to include the value 18 as a literal value in the $gt expression. This allows the aggregation pipeline to compare the age field against the literal value 18 to determine if the person is an adult.
+
+**Create sample documents**
+    
+    
+    db.collection.insertMany([
+      { "name": "John Doe", "age": 30, "city": "New York" },
+      { "name": "Jane Doe", "age": 25, "city": "Los Angeles" },
+      { "name": "Bob Smith", "age": 35, "city": "Chicago" }
+    ]);
+
+**Query example**
+    
+    
+    db.collection.aggregate([
+      {
+        $project: {
+          name: 1,
+          age: 1,
+          city: 1,
+          isAdult: { $gt: ["$age", { $literal: 18 }] }
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    [
+      {
+        "_id": ObjectId("601234567890abcdef012345"),
+        "name": "John Doe",
+        "age": 30,
+        "city": "New York",
+        "isAdult": true
+      },
+      {
+        "_id": ObjectId("601234567890abcdef012346"),
+        "name": "Jane Doe",
+        "age": 25,
+        "city": "Los Angeles",
+        "isAdult": true
+      },
+      {
+        "_id": ObjectId("601234567890abcdef012347"),
+        "name": "Bob Smith",
+        "age": 35,
+        "city": "Chicago",
+        "isAdult": true
+      }
+    ]
+
+## Code examples
+
+To view a code example for using the `$literal` 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('collection');
+    
+      const result = await collection.aggregate([
+        {
+          $project: {
+            name: 1,
+            age: 1,
+            city: 1,
+            isAdult: { $gt: ["$age", { $literal: 18 }] }
+          }
+        }
+      ]).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.collection
+    
+        result = list(collection.aggregate([
+            {
+                '$project': {
+                    'name': 1,
+                    'age': 1,
+                    'city': 1,
+                    'isAdult': { '$gt': ["$age", { '$literal': 18 }] }
+                }
+            }
+        ]))
+    
+        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)
+
+$limit
+
+$ln
+
+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.