AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/slice-projection.md

Summary

Added comprehensive documentation for the $slice projection operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python

Security assessment

This change adds standard feature documentation for the $slice operator, which is a MongoDB projection operator for limiting array elements in query results. There is no mention of security vulnerabilities, patches, or security features. The code examples include standard TLS connection parameters but these are routine security best practices for database connections, not new security documentation.

Diff

diff --git a/documentdb/latest/developerguide/slice-projection.md b/documentdb/latest/developerguide/slice-projection.md
index 8b1378917..3fcf93952 100644
--- a//documentdb/latest/developerguide/slice-projection.md
+++ b//documentdb/latest/developerguide/slice-projection.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#slice-projection "Open PDF")
@@ -1,0 +3,113 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $slice
+
+The `$slice` projection operator limits the number of array elements returned in a query result. It allows you to retrieve a specific number of elements from the start or end of an array field without loading the entire array.
+
+**Parameters**
+
+  * `field`: The array field to project.
+
+  * `count`: Number of elements to return. Positive values return elements from the start, negative values from the end.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$slice` projection operator to return only the first two items from an array field.
+
+**Create sample documents**
+    
+    
+    db.inventory.insertMany([
+      { _id: 1, item: "notebook", tags: ["office", "school", "supplies", "writing"] },
+      { _id: 2, item: "pen", tags: ["office", "writing"] },
+      { _id: 3, item: "folder", tags: ["office", "supplies", "storage", "organization"] }
+    ]);
+
+**Query example**
+    
+    
+    db.inventory.find(
+      {},
+      { item: 1, tags: { $slice: 2 } }
+    )
+
+**Output**
+    
+    
+    { "_id" : 1, "item" : "notebook", "tags" : [ "office", "school" ] }
+    { "_id" : 2, "item" : "pen", "tags" : [ "office", "writing" ] }
+    { "_id" : 3, "item" : "folder", "tags" : [ "office", "supplies" ] }
+
+## Code examples
+
+To view a code example for using the `$slice` projection operator, 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('inventory');
+    
+      const result = await collection.find(
+        {},
+        { projection: { item: 1, tags: { $slice: 2 } } }
+      ).toArray();
+    
+      console.log(JSON.stringify(result, null, 2));
+      await 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['inventory']
+    
+        result = list(collection.find(
+            {},
+            {'item': 1, 'tags': {'$slice': 2}}
+        ))
+    
+        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)
+
+$regex
+
+$size
+
+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.