AWS documentdb documentation change
Summary
Added new documentation page for the $pop operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This is a routine documentation addition for a MongoDB operator ($pop) that removes elements from arrays. The change provides standard usage examples and syntax documentation without any mention of security vulnerabilities, patches, or security features. The code examples include TLS connection parameters which are standard security practices for database connections, but this is not the focus of the documentation change.
Diff
diff --git a/documentdb/latest/developerguide/pop.md b/documentdb/latest/developerguide/pop.md index 8b1378917..ead935136 100644 --- a//documentdb/latest/developerguide/pop.md +++ b//documentdb/latest/developerguide/pop.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#pop "Open PDF") @@ -1,0 +3,118 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $pop + +The `$pop` operator in Amazon DocumentDB is used to remove the first or last element from an array field. It is particularly useful when you need to maintain a fixed-size array or implement a queue-like data structure within a document. + +**Parameters** + + * `field`: The name of the array field to remove an element from. + + * `value`: An integer value that determines the position of the element to remove. A value of `1` removes the last element, while a value of `-1` removes the first element. + + + + +## Example (MongoDB Shell) + +This example demonstrates how to use the `$pop` operator to remove the first and last elements from an array field. + +**Create sample documents** + + + db.users.insertMany([ + { "_id": 1, "name": "John Doe", "hobbies": ["reading", "swimming", "hiking"] }, + { "_id": 2, "name": "Jane Smith", "hobbies": ["cooking", "gardening", "painting"] } + ]) + +**Query example** + + + // Remove the first element from the "hobbies" array + db.users.update({ "_id": 1 }, { $pop: { "hobbies": -1 } }) + + // Remove the last element from the "hobbies" array + db.users.update({ "_id": 2 }, { $pop: { "hobbies": 1 } }) + +**Output** + + + { "_id" : 1, "name" : "John Doe", "hobbies" : [ "swimming", "hiking" ] } + { "_id" : 2, "name" : "Jane Smith", "hobbies" : [ "cooking", "gardening" ] } + +## Code examples + +To view a code example for using the `$pop` 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('users'); + + // Remove the first element from the "hobbies" array + await collection.updateOne({ "_id": 1 }, { $pop: { "hobbies": -1 } }); + + // Remove the last element from the "hobbies" array + await collection.updateOne({ "_id": 2 }, { $pop: { "hobbies": 1 } }); + + const users = await collection.find().toArray(); + console.log(users); + + await 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['users'] + + # Remove the first element from the "hobbies" array + collection.update_one({"_id": 1}, {"$pop": {"hobbies": -1}}) + + # Remove the last element from the "hobbies" array + collection.update_one({"_id": 2}, {"$pop": {"hobbies": 1}}) + + users = list(collection.find()) + print(users) + + client.close() + + example() + + **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) + +$mul + +$position + +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.