AWS documentdb documentation change
Summary
Added new documentation page for the $push aggregation operator with MongoDB Shell, Node.js, and Python code examples
Security assessment
This change adds standard documentation for a database aggregation operator ($push) with code examples. The examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for database connections, but this is not addressing a specific security vulnerability or incident. The change appears to be routine feature documentation.
Diff
diff --git a/documentdb/latest/developerguide/push-aggregation.md b/documentdb/latest/developerguide/push-aggregation.md index 8b1378917..7edecfb52 100644 --- a//documentdb/latest/developerguide/push-aggregation.md +++ b//documentdb/latest/developerguide/push-aggregation.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#push-aggregation "Open PDF") @@ -1,0 +3,126 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $push + +The `$push` aggregation operator returns an array of all values from a specified expression for each group. It is typically used within the `$group` stage to accumulate values into an array. + +**Parameters** + + * `expression`: The expression to evaluate for each document in the group. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$push` operator to collect all product names for each category. + +**Create sample documents** + + + db.sales.insertMany([ + { _id: 1, category: "Electronics", product: "Laptop", amount: 1200 }, + { _id: 2, category: "Electronics", product: "Mouse", amount: 25 }, + { _id: 3, category: "Furniture", product: "Desk", amount: 350 }, + { _id: 4, category: "Furniture", product: "Chair", amount: 150 }, + { _id: 5, category: "Electronics", product: "Keyboard", amount: 75 } + ]); + +**Query example** + + + db.sales.aggregate([ + { + $group: { + _id: "$category", + products: { $push: "$product" } + } + } + ]); + +**Output** + + + [ + { _id: 'Furniture', products: [ 'Desk', 'Chair' ] }, + { _id: 'Electronics', products: [ 'Laptop', 'Mouse', 'Keyboard' ] } + ] + +## Code examples + +To view a code example for using the `$push` aggregation 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('sales'); + + const result = await collection.aggregate([ + { + $group: { + _id: "$category", + products: { $push: "$product" } + } + } + ]).toArray(); + + console.log(result); + 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['sales'] + + result = list(collection.aggregate([ + { + '$group': { + '_id': '$category', + 'products': { '$push': '$product' } + } + } + ])) + + print(result) + client.close() + + example() + + **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) + +$pow + +$project + +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.