Amazon DocumentDB

Amazon DocumentDB is a fully managed NoSQL document database service provided by Amazon Web Services (AWS). It is designed to provide high-performance, scalable, and highly available storage for JSON data.

DocumentDB is compatible with MongoDB, which means that it can be used as a drop-in replacement for MongoDB in existing applications, and supports MongoDB 3.6 APIs and drivers. DocumentDB is designed to be highly scalable and can handle large workloads of read and write requests with low latency.

Here are some working examples of using Amazon DocumentDB:

  1. Creating a DocumentDB cluster: To create a DocumentDB cluster, you can use the AWS Management Console or the AWS Command Line Interface (CLI). Here’s an example using the CLI:
css
aws docdb create-db-cluster --db-cluster-identifier my-cluster --engine-version 3.6.0 --master-username myuser --master-user-password mypassword

This creates a DocumentDB cluster with the identifier my-cluster and the MongoDB 3.6 engine version. The master-username and master-user-password parameters are used to set the username and password for the cluster’s master user.

  1. Creating a DocumentDB database and collection: Once you have a cluster, you can create databases and collections within it. Here’s an example using the MongoDB shell:
css
mongo --host my-cluster.cluster-abc123.us-west-2.docdb.amazonaws.com:27017 --ssl --username myuser --password mypassword

use mydatabase
db.createCollection("mycollection")

This connects to the DocumentDB cluster and creates a database named mydatabase and a collection named mycollection.

  1. Inserting documents into a DocumentDB collection: You can insert JSON documents into a DocumentDB collection using the MongoDB shell. Here’s an example:
perl
db.mycollection.insertOne({ "name": "John", "age": 30, "email": "john@example.com" })

This inserts a new document into the mycollection collection with the fields name, age, and email.

  1. Querying a DocumentDB collection: You can query a DocumentDB collection using MongoDB’s query syntax. Here’s an example:
bash
db.mycollection.find({ "age": { "$gte": 25 } })

This returns all documents in the mycollection collection where the age field is greater than or equal to 25.

Overall, Amazon DocumentDB provides a fully managed, scalable, and high-performance document database service that is easy to use with existing MongoDB applications and APIs.

Author: tonyhughes