AWS documentdb documentation change
Summary
Added new documentation page for the $ifNull operator in Amazon DocumentDB, including operator description, parameters, MongoDB shell example, and code examples in Node.js and Python.
Security assessment
This change adds standard documentation for a MongoDB aggregation operator ($ifNull) with no mention of security vulnerabilities, patches, or security incidents. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are routine secure connection practices, not new security features. The change appears to be routine feature documentation addition.
Diff
diff --git a/documentdb/latest/developerguide/ifNull.md b/documentdb/latest/developerguide/ifNull.md index 8b1378917..89f746851 100644 --- a//documentdb/latest/developerguide/ifNull.md +++ b//documentdb/latest/developerguide/ifNull.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#ifNull "Open PDF") @@ -1,0 +3,140 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $ifNull + +The `$ifNull` operator is used to return a specified value if the input expression evaluates to null or undefined. This operator can be useful in scenarios where you want to provide a default value or handle null/undefined cases. + +**Parameters** + + * `expression`: The expression to evaluate. + + * `replacement`: The value to return if the `<expression>` evaluates to null or undefined. + + + + +## Example (MongoDB Shell) + +The following example demonstrates the usage of the `$ifNull` operator to provide a default value when the `name` field is null or undefined. + +**Create sample documents** + + + db.users.insertMany([ + { _id: 1, name: "John" }, + { _id: 2, name: null }, + { _id: 3 } + ]); + +**Query example** + + + db.users.aggregate([ + { + $project: { + _id: 1, + name: { $ifNull: ["$name", "No Name"] } + } + } + ]); + +**Output** + + + [ + { "_id": 1, "name": "John" }, + { "_id": 2, "name": "No Name" }, + { "_id": 3, "name": "No Name" } + ] + +## Code examples + +To view a code example for using the `$ifNull` 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('users'); + + const pipeline = [ + { + $project: { + _id: 1, + name: { $ifNull: ["$name", "No Name"] } + } + } + ]; + + const cursor = await collection.aggregate(pipeline); + + await cursor.forEach(doc => { + console.log(doc); + }); + + 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.users + + pipeline = [ + { + "$project": { + "_id": 1, + "name": { "$ifNull": ["$name", "No Name"] } + } + } + ] + + result = collection.aggregate(pipeline) + + for doc in result: + print(doc) + + 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) + +$hour + +$in + +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.