A Beginner's Guide: How to Use Amazon DocumentDB in AWS

A Beginner's Guide: How to Use Amazon DocumentDB in AWS


In the ever-evolving landscape of cloud computing, AWS (Amazon Web Services) has become a powerhouse, offering a plethora of services to meet the diverse needs of businesses. One such service that has gained prominence is Amazon DocumentDB, a fully-managed NoSQL database service designed to scale, perform, and simplify the management of MongoDB workloads.

Let's embark on a journey to understand the basics of Amazon DocumentDB and learn how to leverage its capabilities in a straightforward manner.

Getting Started:

  1. Sign in to AWS Console: Log in to your AWS account and navigate to the AWS Management Console.

  2. Access Amazon DocumentDB: From the console, locate the "DocumentDB" service. Click on it to open the Amazon DocumentDB dashboard.

Creating a DocumentDB Cluster:

  1. Click on "Create Cluster": Start by creating a new DocumentDB cluster. Click on the "Create Cluster" button.

  2. Configure Cluster Settings:

    • Choose a cluster identifier and specify a master username and password for authentication.

    • Select the instance class based on your performance requirements.

    • Adjust other settings as needed, such as VPC, Subnet Group, etc.

  3. Add Additional Configuration:

    • Customize additional configurations like enabling storage encryption, backup settings, and maintenance preferences.
  4. Create Cluster: Once you've configured the settings, click on the "Create Cluster" button. This initiates the creation of your Amazon DocumentDB cluster.

Connecting to the Cluster:

  1. Cluster Ready Notification: Wait for the cluster to be created successfully. You will receive a notification once it's ready.

  2. Retrieve Connection Details:

    • Once the cluster is ready, click on its name to view details.

    • Find the connection details, including the cluster endpoint and port.

  3. Connect using MongoDB Client:

    • Use a MongoDB client to connect to your DocumentDB cluster.

    • Input the connection details, including the endpoint, port, username, and password.

  4. Verify Connection: Verify that you can connect successfully by running basic MongoDB commands through the client.

Working with Collections:

  1. Create a Database:

    • Use the MongoDB client to create a new database on your DocumentDB cluster.

    • Example: use mydatabase

  2. Insert Documents:

    • Start populating your database by inserting documents into collections.

    • Example: db.mycollection.insert({ name: "John Doe", age: 30 })

  3. Query Documents:

    • Retrieve data from your collections using queries.

    • Example: db.mycollection.find({ age: { $gt: 25 } })

  4. Update and Delete:

    • Modify and delete documents based on your application's requirements.

    • Example:

      • Update: db.mycollection.update({ name: "John Doe" }, { $set: { age: 31 } })

      • Delete: db.mycollection.remove({ age: { $lt: 30 } })


In this simple guide, we've walked through the essential steps of using Amazon DocumentDB in AWS. From creating a cluster to connecting with a MongoDB client and performing basic database operations, you now have a foundational understanding of how to harness the power of DocumentDB for your applications. As you delve deeper, explore advanced features and optimizations to make the most out of this fully-managed NoSQL database service offered by AWS. Happy coding!

Did you find this article valuable?

Support Sumit Mondal by becoming a sponsor. Any amount is appreciated!