AWS documentdb documentation change
Summary
Added documentation for the $text operator in Amazon DocumentDB, including usage examples in MongoDB Shell, Node.js, and Python with connection strings and sample queries.
Security assessment
This change adds standard documentation for a query operator ($text) with code examples. The connection strings in the examples include TLS parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not new security documentation - it's just showing standard secure connection patterns. There is no evidence of addressing a specific security vulnerability or incident.
Diff
diff --git a/documentdb/latest/developerguide/text.md b/documentdb/latest/developerguide/text.md index 8b1378917..85f0db424 100644 --- a//documentdb/latest/developerguide/text.md +++ b//documentdb/latest/developerguide/text.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#text "Open PDF") @@ -1,0 +3,121 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $text + +The `$text` operator is used to perform full-text search on text-indexed fields within a document collection. This operator allows you to search for documents that contain specific words or phrases, and can be combined with other query operators to filter results based on additional criteria. + +**Parameters** + + * `$search`: The text string to search for. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$text` operator to search for documents containing the word "interest" and filter the results based on a "star_rating" field. + +**Create sample documents** + + + db.test.insertMany([ + { "_id": 1, "star_rating": 4, "comments": "apple is red" }, + { "_id": 2, "star_rating": 5, "comments": "pie is delicious" }, + { "_id": 3, "star_rating": 3, "comments": "apples, oranges - healthy fruit" }, + { "_id": 4, "star_rating": 2, "comments": "bake the apple pie in the oven" }, + { "_id": 5, "star_rating": 5, "comments": "interesting couch" }, + { "_id": 6, "star_rating": 5, "comments": "interested in couch for sale, year 2022" } + ]); + +**Create text index** + + + db.test.createIndex({ comments: "text" }); + +**Query example** + + + db.test.find({$and: [{star_rating: 5}, {$text: {$search: "interest"}}]}) + +**Output** + + + { "_id" : 5, "star_rating" : 5, "comments" : "interesting couch" } + { "_id" : 6, "star_rating" : 5, "comments" : "interested in couch for sale, year 2022" } + +The command above returns documents with a text-indexed field containing any form of "interest" and a "star_rating" equal to 5. + +## Code examples + +To view a code example for using the `$text` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function searchDocuments() { + 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('test'); + + const result = await collection.find({ + $and: [ + { star_rating: 5 }, + { $text: { $search: 'interest' } } + ] + }).toArray(); + + console.log(result); + client.close(); + } + + searchDocuments(); + +Python + + + + from pymongo import MongoClient + + def search_documents(): + 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.test + + result = list(collection.find({ + '$and': [ + {'star_rating': 5}, + {'$text': {'$search': 'interest'}} + ] + })) + + print(result) + client.close() + + search_documents() + + **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) + +$size + +$type + +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.