AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/PRUNE.md

Summary

Added new documentation page for the $$PRUNE system variable used with $redact in aggregation pipelines, including examples in MongoDB Shell, Node.js, and Python

Security assessment

This change adds documentation for the $$PRUNE system variable which is used with the $redact stage for data redaction. While $redact can be used for security purposes to control data exposure, this documentation change itself doesn't address any specific security vulnerability or incident. It's a routine documentation addition explaining a feature that can be used for implementing data access controls.

Diff

diff --git a/documentdb/latest/developerguide/PRUNE.md b/documentdb/latest/developerguide/PRUNE.md
index 8b1378917..b787368f4 100644
--- a//documentdb/latest/developerguide/PRUNE.md
+++ b//documentdb/latest/developerguide/PRUNE.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#PRUNE "Open PDF")
@@ -1,0 +3,137 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $$PRUNE
+
+The `$$PRUNE` system variable is used with the `$redact` stage in the aggregation pipeline to exclude documents or embedded document levels from the results. When a condition evaluates to `$$PRUNE`, the current document or subdocument is removed from the output. It is typically used with `$$DESCEND` (to keep and traverse the document) or `$$KEEP` (to keep the document at all levels).
+
+**Parameters**
+
+None. The `$$PRUNE` system variable is used without any parameters and must be used with `$redact`.
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use `$$PRUNE` with `$redact` to exclude users over 30 years old from the results.
+
+**Create sample documents**
+    
+    
+    db.users.insert([
+      { _id:1, name: "Carlos Salazar", age: 35, address: { street: "123 Main St", city: "Anytown", state: "CA" } },
+      { _id:2, name: "Saanvi Sarkar", age: 28, address: { street: "456 Oak Rd", city: "Someplace", state: "NY" } },
+      { _id:3, name: "Li Juan", age: 42, address: { street: "789 Pine Ave", city: "Springfield", state: "TX" } }
+    ])
+
+**Query example**
+    
+    
+    db.users.aggregate([
+      {
+        $redact: {
+          $cond: {
+            if: { $gt: ["$age", 30] },
+            then: "$$PRUNE",
+            else: "$$DESCEND"
+          }
+        }
+      }
+    ])
+
+**Output**
+    
+    
+    [
+      {
+        "_id": 2,
+        "name": "Saanvi Sarkar",
+        "age": 28,
+        "address": {
+          "street": "456 Oak Rd",
+          "city": "Someplace",
+          "state": "NY"
+        }
+      }
+    ]
+
+## Code examples
+
+To view a code example for using the `$$PRUNE` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    const client = new MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
+    
+    async function main() {
+      await client.connect();
+      const db = client.db('test');
+      const users = db.collection('users');
+    
+      const result = await users.aggregate([
+        {
+          $redact: {
+            $cond: {
+              if: { $gt: ["$age", 30] },
+              then: "$$PRUNE",
+              else: "$$DESCEND"
+            }
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+      await client.close();
+    }
+    
+    main();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+    db = client['test']
+    users = db['users']
+    
+    result = list(users.aggregate([
+        {
+            '$redact': {
+                '$cond': {
+                    'if': { '$gt': ['$age', 30] },
+                    'then': '$$PRUNE',
+                    'else': '$$DESCEND'
+                }
+            }
+        }
+    ]))
+    
+    print(result)
+    client.close()
+
+![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)
+
+$$KEEP
+
+$ROOT
+
+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.