AWS documentdb documentation change
Summary
Added new documentation page for the $type aggregation operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python.
Security assessment
This change adds documentation for a standard database operator ($type) used for data type identification. There is no evidence of security vulnerability fixes, security patches, or security incident remediation. The code examples show standard TLS connection parameters which are normal security practices for database connections, but this is not new security documentation.
Diff
diff --git a/documentdb/latest/developerguide/type-aggregation.md b/documentdb/latest/developerguide/type-aggregation.md index 8b1378917..3e9f39bc0 100644 --- a//documentdb/latest/developerguide/type-aggregation.md +++ b//documentdb/latest/developerguide/type-aggregation.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#type-aggregation "Open PDF") @@ -1,0 +3,130 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $type + +The `$type` aggregation operator returns the BSON data type of a specified field. This is useful for identifying the data type of field values during aggregation operations. + +**Parameters** + + * `expression`: The field or expression whose type to return. + + + + +## Example (MongoDB Shell) + +The following example demonstrates using the `$type` operator to identify the data type of the price field for each product. + +**Create sample documents** + + + db.inventory.insertMany([ + { _id: 1, item: "Notebook", price: 15.99 }, + { _id: 2, item: "Pen", price: "2.50" }, + { _id: 3, item: "Eraser", price: 1 }, + { _id: 4, item: "Ruler", price: null } + ]); + +**Query example** + + + db.inventory.aggregate([ + { + $project: { + item: 1, + price: 1, + priceType: { $type: "$price" } + } + } + ]); + +**Output** + + + [ + { _id: 1, item: 'Notebook', price: 15.99, priceType: 'double' }, + { _id: 2, item: 'Pen', price: '2.50', priceType: 'string' }, + { _id: 3, item: 'Eraser', price: 1, priceType: 'int' }, + { _id: 4, item: 'Ruler', price: null, priceType: 'null' } + ] + +## Code examples + +To view a code example for using the `$type` aggregation operator, 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('inventory'); + + const result = await collection.aggregate([ + { + $project: { + item: 1, + price: 1, + priceType: { $type: "$price" } + } + } + ]).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['inventory'] + + result = list(collection.aggregate([ + { + '$project': { + 'item': 1, + 'price': 1, + 'priceType': { '$type': '$price' } + } + } + ])) + + 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) + +$trim + +$unset + +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.