AWS documentdb documentation change
Summary
Added new documentation page for the $natural operator in Amazon DocumentDB, including explanation, MongoDB shell example, and code examples in Node.js and Python
Security assessment
This change adds routine documentation for a database operator ($natural) used for sorting documents in insertion order. The code examples include standard TLS connection parameters but these are not new security features. There is no evidence of addressing a specific security vulnerability, weakness, or incident in this documentation addition.
Diff
diff --git a/documentdb/latest/developerguide/natural.md b/documentdb/latest/developerguide/natural.md index 8b1378917..ba565e22a 100644 --- a//documentdb/latest/developerguide/natural.md +++ b//documentdb/latest/developerguide/natural.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#natural "Open PDF") @@ -1,0 +3,110 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $natural + +The `$natural` operator in Amazon DocumentDB is used to sort the documents in their natural order, which is the order in which they were inserted into the collection. This is in contrast to the default sorting behavior, which is to sort the documents based on the values of the specified fields. + +**Parameters** + +None + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$natural` operator to sort the documents in a collection in their natural order. + +**Create sample documents** + + + db.people.insertMany([ + { "_id": 1, "name": "María García", "age": 28 }, + { "_id": 2, "name": "Arnav Desai", "age": 32 }, + { "_id": 3, "name": "Li Juan", "age": 25 }, + { "_id": 4, "name": "Carlos Salazar", "age": 41 }, + { "_id": 5, "name": "Sofia Martínez", "age": 35 } + ]); + +**Query example** + + + db.people.find({}, { "_id": 1, "name": 1 }).sort({ "$natural": 1 }); + +**Output** + + + [ + { "_id": 1, "name": "María García" }, + { "_id": 2, "name": "Arnav Desai" }, + { "_id": 3, "name": "Li Juan" }, + { "_id": 4, "name": "Carlos Salazar" }, + { "_id": 5, "name": "Sofia Martínez" } + ] + +The query sorts the documents in the collection in their natural order, which is the order in which they were inserted. + +## Code examples + +To view a code example for using the `$natural` command, 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('people'); + + const documents = await collection.find({}, { projection: { _id: 1, name: 1 } }) + .sort({ $natural: 1 }) + .toArray(); + + console.log(documents); + + 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['people'] + + documents = list(collection.find({}, {'_id': 1, 'name': 1}).sort('$natural', 1)) + print(documents) + + 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) + +$multiply + +$ne + +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.