AWS documentdb documentation change
Summary
Added new documentation page for the $regex operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds routine documentation for a query operator ($regex) with standard usage examples. The code examples include TLS connection parameters (tls=true, tlsCAFile) which are standard secure connection practices, but this is not introducing new security documentation - it's showing standard secure connection patterns that should already be used. There is no evidence of addressing a specific security vulnerability or incident.
Diff
diff --git a/documentdb/latest/developerguide/regex.md b/documentdb/latest/developerguide/regex.md index 8b1378917..3e8dd91b6 100644 --- a//documentdb/latest/developerguide/regex.md +++ b//documentdb/latest/developerguide/regex.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#regex "Open PDF") @@ -1,0 +3,109 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $regex + +The `$regex` operator allows you to perform regular expression matching on string fields. It is a powerful tool for searching and filtering documents based on complex patterns. + +**Parameters** + + * `regular expression`: The regular expression pattern to match against the field. + + * `$options`: (optional) Provides options to modify the search behavior, such as case-sensitivity, global matching, etc. + + + + +## Example (MongoDB Shell) + +The following example demonstrates the usage of the `$regex` operator to search for documents where the "name" field matches a specific pattern. + +**Create sample documents** + + + db.users.insertMany([ + { name: "John Doe" }, + { name: "Jane Smith" }, + { name: "Alice Johnson" }, + { name: "Bob Williams" }, + { name: "Charlie Davis" } + ]); + +**Query example** + + + db.users.find({ name: { $regex: /^A/ } }) + +**Output** + + + [ + { "_id" : ObjectId("..."), "name" : "Alice Johnson" } + ] + +This query will return all documents where the "name" field starts with the letter "A". + +## Code examples + +To view a code example for using the `$regex` 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('users'); + + const results = await collection.find({ name: { $regex: /^A/ } }).toArray(); + console.log(results); + + await client.close(); + } + + main(); + +Python + + + + from pymongo import MongoClient + + def main(): + 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'] + + results = list(collection.find({ 'name': { '$regex': '^A' } })) + print(results) + + client.close() + + if __name__ == "__main__": + main() + + **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) + +$or + +$slice + +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.