AWS documentdb documentation change
Summary
Added documentation for the $type operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This is a routine documentation addition for a MongoDB operator ($type) that checks data types of fields. There is no mention of security vulnerabilities, patches, or security-related features. The change appears to be standard feature documentation without any security context.
Diff
diff --git a/documentdb/latest/developerguide/type.md b/documentdb/latest/developerguide/type.md index 8b1378917..65a392e32 100644 --- a//documentdb/latest/developerguide/type.md +++ b//documentdb/latest/developerguide/type.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#type "Open PDF") @@ -1,0 +3,123 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $type + +The `$type` operator is used to check the data type of a field in a document. It can used when type-specific operations or validations are needed. The `$type` operator returns the BSON type of the evaluated expression. The returned type is a string, which corresponds to the type of the field or expression. + +Planner version 2.0 added index support for `$type`. + +**Parameters** + + * `expression` : The expression to evaluate. + + + + +## Example (MongoDB Shell) + +**Create sample documents** + + + db.documents.insertMany([ + { _id: 1, name: "John", age: 30, email: "[email protected]" }, + { _id: 2, name: "Jane", age: "25", email: 123456 }, + { _id: 3, name: 123, age: true, email: null } + ]); + +**Query example** + + + db.documents.find({ + $or: [ + { age: { $type: "number" } }, + { email: { $type: "string" } }, + { name: { $type: "string" } } + ] + }) + +**Output** + + + [ + { "_id": 1, "name": "John", "age": 30, "email": "[email protected]" }, + { "_id": 2, "name": "Jane", "age": "25", "email": 123456 } + ] + +This query will return the documents where the `age` field is of type "number", the `email` field is of type "string", and the `name` field is of type "string". + +## Code examples + +To view a code example for using the `$type` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function findByType() { + 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('documents'); + + const results = await collection.find({ + $or: [ + { age: { $type: 'number' } }, + { email: { $type: 'string' } }, + { name: { $type: 'string' } } + ] + }).toArray(); + + console.log(results); + client.close(); + } + + findByType(); + +Python + + + + from pymongo import MongoClient + + def find_by_type(): + 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['documents'] + + results = list(collection.find({ + '$or': [ + {'age': {'$type': 'number'}}, + {'email': {'$type': 'string'}}, + {'name': {'$type': 'string'}} + ] + })) + + print(results) + client.close() + + find_by_type() + + **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) + +$text + +Update operators + +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.