AWS documentdb documentation change
Summary
Added new documentation page for the $sort aggregation stage in Amazon DocumentDB, including syntax, parameters, MongoDB shell example, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a MongoDB aggregation operator ($sort) with no mention of security vulnerabilities, patches, or security incidents. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are routine security best practices for DocumentDB connections, but these are not new security features being documented - they're standard connection parameters shown in examples.
Diff
diff --git a/documentdb/latest/developerguide/sort.md b/documentdb/latest/developerguide/sort.md index 8b1378917..010f0b212 100644 --- a//documentdb/latest/developerguide/sort.md +++ b//documentdb/latest/developerguide/sort.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#sort "Open PDF") @@ -1,0 +3,116 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $sort + +The `$sort` aggregation stage orders documents in the pipeline based on specified field values. Documents are arranged in ascending or descending order according to the sort criteria provided. + +**Parameters** + + * `field`: The field name to sort by. + + * `order`: Use `1` for ascending order or `-1` for descending order. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$sort` stage to order products by price in descending order. + +**Create sample documents** + + + db.products.insertMany([ + { _id: 1, name: "Laptop", category: "Electronics", price: 1200 }, + { _id: 2, name: "Mouse", category: "Electronics", price: 25 }, + { _id: 3, name: "Desk", category: "Furniture", price: 350 }, + { _id: 4, name: "Chair", category: "Furniture", price: 150 }, + { _id: 5, name: "Monitor", category: "Electronics", price: 400 } + ]); + +**Query example** + + + db.products.aggregate([ + { $sort: { price: -1 } } + ]); + +**Output** + + + [ + { _id: 1, name: 'Laptop', category: 'Electronics', price: 1200 }, + { _id: 5, name: 'Monitor', category: 'Electronics', price: 400 }, + { _id: 3, name: 'Desk', category: 'Furniture', price: 350 }, + { _id: 4, name: 'Chair', category: 'Furniture', price: 150 }, + { _id: 2, name: 'Mouse', category: 'Electronics', price: 25 } + ] + +## Code examples + +To view a code example for using the `$sort` aggregation stage, 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('products'); + + const result = await collection.aggregate([ + { $sort: { price: -1 } } + ]).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['products'] + + result = list(collection.aggregate([ + { '$sort': { 'price': -1 } } + ])) + + 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) + +$size + +$split + +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.