AWS Security ChangesHomeSearch

AWS documentdb documentation change

Service: documentdb · 2026-03-31 · Documentation low

File: documentdb/latest/developerguide/exists.md

Summary

Added documentation for the $exists operator in Amazon DocumentDB, including usage with sparse indexes, parameters, MongoDB shell examples, and code examples in Node.js and Python

Security assessment

This change adds routine documentation for a MongoDB operator ($exists) and its usage with sparse indexes. While it includes connection strings with authentication parameters (username/password), this is standard database documentation and doesn't address any specific security vulnerability or weakness. The documentation shows proper TLS usage (tls=true) and certificate validation (tlsCAFile=global-bundle.pem), which are security best practices but not new security features.

Diff

diff --git a/documentdb/latest/developerguide/exists.md b/documentdb/latest/developerguide/exists.md
index 8b1378917..75ba45e13 100644
--- a//documentdb/latest/developerguide/exists.md
+++ b//documentdb/latest/developerguide/exists.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#exists "Open PDF")
@@ -1,0 +3,109 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $exists
+
+The `$exists` operator is used to check whether a field exists in a document or not. `$exists` particularly useful when working with sparse indexes in Amazon DocumentDB, where the indexed field may not be present in all documents.
+
+To use a sparse index that you have created in a query, you must use the `$exists` clause on the fields that cover the index. If you omit `$exists`, Amazon DocumentDB will not use the sparse index for the query.
+
+**Parameters**
+
+  * `field`: The field name to check for existence.
+
+  * `value`: A boolean value (`true` or `false`) that specifies whether the field should exist (`true`) or not exist (`false`) in the matching documents.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates the use of the `$exists` operator with a sparse index on the `special_diets` field in the `food` collection.
+
+**Create sample documents**
+    
+    
+    db.food.insertMany([
+      { _id: 1, name: "Apple", special_diets: ["vegetarian", "gluten-free"] },
+      { _id: 2, name: "Broccoli" },
+      { _id: 3, name: "Chicken", special_diets: ["dairy-free"] }
+    ]);
+
+**Create a sparse index on the `special_diets` field**
+    
+    
+    db.food.createIndex({ "special_diets": 1 }, { sparse: true, name: "special_diets_sparse_asc" });
+
+**Query example**
+    
+    
+    db.food.find({ "special_diets": { $exists: true } });
+
+**Output**
+    
+    
+    [
+      { "_id" : 1, "name" : "Apple", "special_diets" : [ "vegetarian", "gluten-free" ] },
+      { "_id" : 3, "name" : "Chicken", "special_diets" : [ "dairy-free" ] }
+    ]
+
+## Code examples
+
+To view a code example for using the `$exists` 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('food');
+    
+      const result = await collection.find({ "special_diets": { $exists: true } }).toArray();
+      console.log(result);
+    
+      await client.close();
+    }
+    
+    main();
+
+Python
+    
+    
+    
+    import pymongo
+    
+    client = pymongo.MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+    db = client['test']
+    collection = db['food']
+    
+    result = list(collection.find({"special_diets": {"$exists": True}}))
+    print(result)
+    
+    client.close()
+
+![Warning](https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png) **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)
+
+$eq
+
+$expr
+
+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.