AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/limit.md

Summary

Added comprehensive documentation for the $limit operator in Amazon DocumentDB, including usage examples in MongoDB Shell, Node.js, and Python

Security assessment

This change adds standard documentation for the $limit operator functionality. The code examples show connection strings with TLS enabled (tls=true) and certificate validation (tlsCAFile=global-bundle.pem), which are security best practices, but this is not new security documentation - it's standard secure connection configuration that was likely already documented elsewhere. There is no evidence this addresses a specific security vulnerability or incident.

Diff

diff --git a/documentdb/latest/developerguide/limit.md b/documentdb/latest/developerguide/limit.md
index 8b1378917..2e1bf06e7 100644
--- a//documentdb/latest/developerguide/limit.md
+++ b//documentdb/latest/developerguide/limit.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#limit "Open PDF")
@@ -1,0 +3,147 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $limit
+
+The `$limit` operator in Amazon DocumentDB is used to restrict the number of documents returned by a query. It is similar to the MongoDB `$limit` operator, but there are some specific considerations when using it with Amazon DocumentDB.
+
+In Amazon DocumentDB, the `$limit` operator is useful for pagination, where you want to retrieve a subset of the total matching documents. It allows you to control the number of documents returned in each response, improving performance and reducing the amount of data transferred over the network.
+
+**Parameters**
+
+  * `limit`: The maximum number of documents to return. This must be a non-negative integer value.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$limit` operator to return a maximum of one document that matches the given filter.
+
+**Create sample documents**
+    
+    
+    db.test.insertMany([
+      { "_id": 1, "star_rating": 4, "comments": "apple is red" },
+      { "_id": 2, "star_rating": 5, "comments": "comfortable couch" },
+      { "_id": 3, "star_rating": 3, "comments": "apples, oranges - healthy fruit" },
+      { "_id": 4, "star_rating": 5, "comments": "this is a great couch" },
+      { "_id": 5, "star_rating": 5, "comments": "interesting couch" }
+    ]);
+
+**Query example**
+    
+    
+    db.test.createIndex({ comments: "text" });
+    
+    db.test.find({
+      $and: [
+        { star_rating: 5 },
+        { $text: { $search: "couch" } }
+      ]
+    }).limit(1);
+
+**Output**
+    
+    
+    [ { _id: 2, star_rating: 5, comments: 'comfortable couch' } ]
+
+## Code examples
+
+To view a code example for using the `$limit` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function limitExample() {
+      const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
+    
+      try {
+          await client.connect();
+          
+          const db = client.db('test');
+          const collection = db.collection('test');
+    
+          await collection.createIndex({ comments: 'text' });
+    
+          const query = {
+            $and: [
+              { star_rating: 5 },
+              { $text: { $search: "couch" } }
+            ]
+          };
+    
+          const result = await collection.find(query).limit(1).toArray();
+    
+          console.log(result);
+    
+        } catch (err) {
+            console.error("Error:", err);
+        } finally {
+            await client.close();
+        }
+    
+    }
+    
+    limitExample();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    def limit_example():
+        try:
+            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['test']
+    
+            collection.create_index([('comments', 'text')])
+    
+            query = {
+                '$and': [
+                    {'star_rating': 5},
+                    {'$text': {'$search': 'couch'}}
+                ]
+            }
+    
+            result = collection.find(query).limit(1)
+    
+            for doc in result:
+                print(doc)
+    
+        except Exception as e:
+            print(f"An error occurred: {e}")
+        
+        finally:
+            client.close()
+    
+    limit_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)
+
+$let
+
+$literal
+
+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.