AWS documentdb documentation change
Summary
Added new documentation page for the $ROOT operator in Amazon DocumentDB, including description, parameters, MongoDB Shell example, and code examples in Node.js and Python.
Security assessment
This change adds routine documentation for a database operator ($ROOT) with standard code examples. There is no mention of security vulnerabilities, patches, or security incidents. The examples include standard connection strings with placeholders and do not introduce any security-specific content.
Diff
diff --git a/documentdb/latest/developerguide/ROOT.md b/documentdb/latest/developerguide/ROOT.md index 8b1378917..c17848ab6 100644 --- a//documentdb/latest/developerguide/ROOT.md +++ b//documentdb/latest/developerguide/ROOT.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#ROOT "Open PDF") @@ -1,0 +3,197 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $ROOT + +The `$ROOT` operator in Amazon DocumentDB is used to reference the entire input document within an aggregation pipeline. It allows you to access and manipulate the complete document, including all its nested fields and structures. + +**Parameters** + +None + +## Example (MongoDB Shell) + +This example demonstrates using `$ROOT` to create an audit log that captures the complete original document along with metadata about when it was processed. + +**Create sample documents** + + + db.orders.insertMany([ + { + _id: 1, + orderId: "ORD-2024-001", + customer: "María García", + email: "marí[email protected]", + items: [ + { product: "Laptop", quantity: 1, price: 1299.99 } + ], + totalAmount: 1299.99 + }, + { + _id: 2, + orderId: "ORD-2024-002", + customer: "Arnav Desai", + email: "[email protected]", + items: [ + { product: "Mouse", quantity: 2, price: 29.99 }, + { product: "Keyboard", quantity: 1, price: 89.99 } + ], + totalAmount: 149.97 + } + ]); + +**Query example** + + + db.orders.aggregate([ + { + $project: { + processedAt: new Date(), + originalDocument: "$$ROOT", + summary: { + $concat: [ + "Order ", + "$orderId", + " for ", + "$customer", + " - Total: $", + { $toString: "$totalAmount" } + ] + } + } + } + ]); + +**Output** + + + [ + { + _id: 1, + processedAt: ISODate('2025-11-24T20:43:51.492Z'), + originalDocument: { + _id: 1, + orderId: 'ORD-2024-001', + customer: 'María García', + email: 'marí[email protected]', + items: [ { product: 'Laptop', quantity: 1, price: 1299.99 } ], + totalAmount: 1299.99 + }, + summary: 'Order ORD-2024-001 for María García - Total: $1299.99' + }, + { + _id: 2, + processedAt: ISODate('2025-11-24T20:43:51.492Z'), + originalDocument: { + _id: 2, + orderId: 'ORD-2024-002', + customer: 'Arnav Desai', + email: '[email protected]', + items: [ + { product: 'Mouse', quantity: 2, price: 29.99 }, + { product: 'Keyboard', quantity: 1, price: 89.99 } + ], + totalAmount: 149.97 + }, + summary: 'Order ORD-2024-002 for Arnav Desai - Total: $149.97' + } + ] + +## Code examples + +To view a code example for using the `$ROOT` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function createAuditLog() { + 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 orders = db.collection('orders'); + + const result = await orders.aggregate([ + { + $project: { + processedAt: new Date(), + originalDocument: "$$ROOT", + summary: { + $concat: [ + "Order ", + "$orderId", + " for ", + "$customer", + " - Total: $", + { $toString: "$totalAmount" } + ] + } + } + } + ]).toArray(); + + console.log(result); + await client.close(); + } + + createAuditLog(); + +Python + + + + from pymongo import MongoClient + from datetime import datetime + + def create_audit_log(): + client = MongoClient('mongodb://username:password@docdb-cluster.cluster-123456789.us-east-1.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') + db = client['test'] + collection = db['orders'] + + result = list(collection.aggregate([ + { + '$project': { + 'processedAt': datetime.now(), + 'originalDocument': '$$ROOT', + 'summary': { + '$concat': [ + "Order ", + "$orderId", + " for ", + "$customer", + " - Total: $", + { '$toString': "$totalAmount" } + ] + } + } + } + ])) + + print(result) + client.close() + + create_audit_log() + + **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) + +$$PRUNE + +$abs + +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