AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/indexOfCP.md

Summary

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

Security assessment

This change adds routine documentation for a MongoDB aggregation operator ($indexOfCP) that finds substring positions in strings. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are normal security best practices for database connections, but there is no evidence this addresses a specific security vulnerability or incident. The change appears to be standard feature documentation.

Diff

diff --git a/documentdb/latest/developerguide/indexOfCP.md b/documentdb/latest/developerguide/indexOfCP.md
index 8b1378917..f512371f9 100644
--- a//documentdb/latest/developerguide/indexOfCP.md
+++ b//documentdb/latest/developerguide/indexOfCP.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#indexOfCP "Open PDF")
@@ -1,0 +3,113 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $indexOfCP
+
+The `$indexOfCP` operator in Amazon DocumentDB is used to find the index, in code points (CP), of the first occurrence of a specified substring within a string expression. This can be useful when parsing and extracting content from string fields.
+
+**Parameters**
+
+  * `string expression`: The string to search.
+
+  * `substring`: The substring to search for.
+
+  * `[<start>]`: (optional) The position to start the search (zero-based index). Default is 0.
+
+
+
+
+## Example (MongoDB Shell)
+
+In this example, we use the `$indexOfCP` operator to find the index of the first occurrence of the hyphen character - in the Desk field of each document.
+
+**Create sample documents**
+    
+    
+    db.people.insertMany([
+      { "_id":1, "name":"John Doe", "Manager":"Jane Doe", "Role":"Developer", "Desk": "Düsseldorf-BVV-021"},
+      { "_id":2, "name":"John Stiles", "Manager":"Jane Doe", "Role":"Manager", "Desk": "Munich-HGG-32a"},
+      { "_id":3, "name":"Richard Roe", "Manager":"Jorge Souza", "Role":"Product", "Desk": "Cologne-ayu-892.50"},
+      { "_id":4, "name":"Mary Major", "Manager":"Jane Doe", "Role":"Solution Architect", "Desk": "Dortmund-Hop-78"}
+    ])
+
+**Query example**
+    
+    
+    db.people.aggregate([
+      { $project: { stateLocation: { $indexOfCP: [ "$Desk", "-"] } } }
+    ])
+
+**Output**
+    
+    
+    { "_id" : 1, "stateLocation" : 10 }
+    { "_id" : 2, "stateLocation" : 6 }
+    { "_id" : 3, "stateLocation" : 7 }
+    { "_id" : 4, "stateLocation" : 8 }
+
+## Code examples
+
+To view a code example for using the `$indexOfCP` 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('people');
+    
+      const result = await collection.aggregate([
+        { $project: { stateLocation: { $indexOfCP: [ "$Desk", "-"] } } }
+      ]).toArray();
+    
+      console.log(result);
+    
+      await client.close();
+    }
+    
+    main();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    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['people']
+    
+    result = list(collection.aggregate([
+        { '$project': { 'stateLocation': { '$indexOfCP': [ '$Desk', '-' ] } } }
+    ]))
+    
+    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)
+
+$indexOfBytes
+
+$indexStats
+
+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.