AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/indexOfArray.md

Summary

Added new documentation page for the $indexOfArray operator in Amazon DocumentDB, including description, parameters, MongoDB shell example, and code examples in Node.js and Python

Security assessment

This is a routine documentation addition for a MongoDB operator ($indexOfArray) used for finding array element indices. The change includes standard code examples with connection strings that use TLS encryption (tls=true) and CA certificates, which is standard security practice but not evidence of addressing a specific security issue. No security vulnerabilities, weaknesses, or incidents are mentioned in the documentation.

Diff

diff --git a/documentdb/latest/developerguide/indexOfArray.md b/documentdb/latest/developerguide/indexOfArray.md
index 8b1378917..1754e5bcc 100644
--- a//documentdb/latest/developerguide/indexOfArray.md
+++ b//documentdb/latest/developerguide/indexOfArray.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#indexOfArray "Open PDF")
@@ -1,0 +3,127 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $indexOfArray
+
+The `$indexOfArray` operator in Amazon DocumentDB is used to find the index of the first occurrence of a specified element in an array. This operator returns the zero-based index position of the first element in the array that matches the specified value. If the value is not found, it returns -1.
+
+**Parameters**
+
+  * `array`: The array to search.
+
+  * `value`: The value to search for in the array.
+
+  * `start`: (optional) The position in the array to start the search from. The default value is 0.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the $indexOfArray operator to find the index of the first occurrence of the element "mango" in the "fruits" array for each document.
+
+**Create sample documents**
+    
+    
+    db.collection.insertMany([
+      { _id: 1, fruits: ["apple", "banana", "cherry", "durian"] },
+      { _id: 2, fruits: ["mango", "orange", "pineapple"] },
+      { _id: 3, fruits: ["kiwi", "lemon", "mango"] }
+    ]);
+
+**Query example**
+    
+    
+    db.collection.aggregate([
+      {
+        $project: {
+          _id: 1,
+          fruitIndex: { $indexOfArray: ["$fruits", "mango"] }
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    { "_id" : 1, "fruitIndex" : 1 }
+    { "_id" : 2, "fruitIndex" : 0 }
+    { "_id" : 3, "fruitIndex" : 2 }
+
+## Code examples
+
+To view a code example for using the `$indexOfArray` 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('collection');
+    
+      const result = await collection.aggregate([
+        {
+          $project: {
+            _id: 1,
+            fruitIndex: { $indexOfArray: ["$fruits", "mango"] }
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+      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['collection']
+    
+        result = list(collection.aggregate([
+            {
+                '$project': {
+                    '_id': 1,
+                    'fruitIndex': { '$indexOfArray': ["$fruits", "mango"] }
+                }
+            }
+        ]))
+    
+        print(result)
+        client.close()
+    
+    example()
+
+![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)
+
+$in
+
+$indexOfBytes
+
+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.