AWS documentdb documentation change
Summary
Added documentation for the $abs aggregation operator in Amazon DocumentDB with examples in MongoDB Shell, Node.js, and Python
Security assessment
This change adds standard documentation for a mathematical operator ($abs) in Amazon DocumentDB. The examples show typical usage patterns for aggregation pipelines and include standard connection strings with TLS parameters. There is no evidence of addressing a security vulnerability, weakness, or incident. The connection strings shown include standard security parameters (tls=true, tlsCAFile) that are already documented elsewhere.
Diff
diff --git a/documentdb/latest/developerguide/abs.md b/documentdb/latest/developerguide/abs.md index 8b1378917..0879466f7 100644 --- a//documentdb/latest/developerguide/abs.md +++ b//documentdb/latest/developerguide/abs.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#abs "Open PDF") @@ -1,0 +3,122 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $abs + +The `$abs` operator in Amazon DocumentDB returns the absolute value of a number. It can be used in the aggregation pipeline to perform mathematical operations on numeric fields. + +**Parameters** + + * `number`: The numeric expression for which the absolute value will be returned. + + + + +## Example (MongoDB Shell) + +This example demonstrates the usage of the `$abs` operator to find the absolute value of a numeric field. + +**Create sample documents** + + + db.numbers.insertMany([ + { "_id": 1, "value": -5 }, + { "_id": 2, "value": 10 }, + { "_id": 3, "value": -3.14 }, + { "_id": 4, "value": 0 } + ]); + +**Query example** + + + db.numbers.aggregate([ + { $project: { + "_id": 1, + "absolute_value": { $abs: "$value" } + }} + ]); + +**Output** + + + [ + { "_id": 1, "absolute_value": 5 }, + { "_id": 2, "absolute_value": 10 }, + { "_id": 3, "absolute_value": 3.14 }, + { "_id": 4, "absolute_value": 0 } + ] + +## Code examples + +To view a code example for using the `$abs` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function main() { + 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('numbers'); + + const result = await collection.aggregate([ + { $project: { + "_id": 1, + "absolute_value": { $abs: "$value" } + }} + ]).toArray(); + + console.log(result); + await client.close(); + } + + main(); + +Python + + + + from pymongo import MongoClient + + def main(): + 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['numbers'] + + result = list(collection.aggregate([ + { '$project': { + "_id": 1, + "absolute_value": { "$abs": "$value" } + }} + ])) + + print(result) + client.close() + + if __name__ == "__main__": + main() + + **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) + +$ROOT + +$add + +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.