AWS documentdb documentation change
Summary
Added new documentation page for the $rand operator in Amazon DocumentDB (new from version 8.0), including syntax, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds documentation for a new operator without any security context. There is no evidence of addressing security vulnerabilities or documenting security features. The code examples show standard TLS connections but this is routine secure connection practice.
Diff
diff --git a/documentdb/latest/developerguide/rand.md b/documentdb/latest/developerguide/rand.md index 8b1378917..84caa8598 100644 --- a//documentdb/latest/developerguide/rand.md +++ b//documentdb/latest/developerguide/rand.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#rand "Open PDF") @@ -1,0 +3,127 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $rand + +New from version 8.0 + +The `$rand` operator in Amazon DocumentDB is used to generate a random number between 0 and 1. + +**Parameters** + +None + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$rand` operator to randomly select two documents from the `temp` collection. + +**Create sample documents** + + + db.items.insertMany([ + { "name": "pencil", "quantity": 110 }, + { "name": "pen", "quantity": 159 } + ]) + +**Query example** + + + db.items.aggregate([ + { + $project: { + randomValue: { $rand: {} } + } + } + ]) + +**Output** + + + [ + { + _id: ObjectId('6924a5edd66dcae121d29517'), + randomValue: 0.8615243955294392 + }, + { + _id: ObjectId('6924a5edd66dcae121d29518'), + randomValue: 0.22815483022099903 + } + ] + +## Code examples + +To view a code example for using the `$rand` 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('items'); + + const result = await collection.aggregate([ + { + $project: { + randomValue: { $rand: {} } + } + } + ]).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['items'] + + result = list(collection.aggregate([ + { + "$project": { + "randomValue": { "$rand": {} } + } + } + ])) + + 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) + +$project + +$range + +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.