AWS documentdb documentation change
Summary
Added new documentation page for the $objectToArray aggregation operator in Amazon DocumentDB, including detailed explanation, parameters, MongoDB Shell example with sample data and queries, and code examples in Node.js and Python.
Security assessment
This change adds standard documentation for a database aggregation operator ($objectToArray) with usage examples. There is no mention of security vulnerabilities, patches, or security features. The code examples include standard connection strings with TLS parameters (tls=true, tlsCAFile) which are standard security practices for encrypted connections, but this is routine security documentation rather than addressing a specific security issue.
Diff
diff --git a/documentdb/latest/developerguide/objectToArray.md b/documentdb/latest/developerguide/objectToArray.md index 8b1378917..bb628224f 100644 --- a//documentdb/latest/developerguide/objectToArray.md +++ b//documentdb/latest/developerguide/objectToArray.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#objectToArray "Open PDF") @@ -1,0 +3,207 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $objectToArray + +The `$objectToArray` aggregation operator in Amazon DocumentDB converts an object (or document) into an array. The input to the operator is a document, and the output consists of an array element for each field-value pair in the input document. This operator is useful when you need to work with the individual fields of a document as an array, such as when you want to find the document with the maximum or minimum value for a particular field. + +**Parameters** + + * `expression`: The document expression to convert into an array. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$objectToArray` operator to find the document with the maximum inventory for a video rental store chain. + +**Create sample documents** + + + db.videos.insertMany([ + { + "_id": 1, + "name": "Live Soft", + "inventory": { + "Des Moines": 1000, + "Ames": 500 + } + }, + { + "_id": 2, + "name": "Top Pilot", + "inventory": { + "Mason City": 250, + "Des Moines": 1000 + } + }, + { + "_id": 3, + "name": "Romancing the Rock", + "inventory": { + "Mason City": 250, + "Ames": 500 + } + }, + { + "_id": 4, + "name": "Bravemind", + "inventory": { + "Mason City": 250, + "Des Moines": 1000, + "Ames": 500 + } + } + ]); + +**Query example** + + + db.videos.aggregate([ + { + $project: { + name: 1, + videos: { + $objectToArray: "$inventory" + } + } + }, + { + $unwind: "$videos" + }, + { + $group: { + _id: "$name", + maxInventory: { + $max: "$videos.v" + } + } + } + ]); + +**Output** + + + [ + { + "_id": "Bravemind", + "maxInventory": 1000 + }, + { + "_id": "Live Soft", + "maxInventory": 1000 + }, + { + "_id": "Romancing the Rock", + "maxInventory": 500 + }, + { + "_id": "Top Pilot", + "maxInventory": 1000 + } + ] + +## Code examples + +To view a code example for using the `$objectToArray` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function findMaxInventory() { + 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 videos = db.collection('videos'); + + const result = await videos.aggregate([ + { + $project: { + name: 1, + videos: { + $objectToArray: "$inventory" + } + } + }, + { + $unwind: "$videos" + }, + { + $group: { + _id: "$name", + maxInventory: { + $max: "$videos.v" + } + } + } + ]).toArray(); + + console.log(result); + client.close(); + } + + findMaxInventory(); + +Python + + + + from pymongo import MongoClient + + def find_max_inventory(): + client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') + db = client['test'] + videos = db['videos'] + + result = list(videos.aggregate([ + { + '$project': { + 'name': 1, + 'videos': { + '$objectToArray': '$inventory' + } + } + }, + { + '$unwind': '$videos' + }, + { + '$group': { + '_id': '$name', + 'maxInventory': { + '$max': '$videos.v' + } + } + } + ])) + + print(result) + client.close() + + find_max_inventory() + + **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) + +$not