Skip to content

Document Databases#

  • User needs: Data storage, Data query
  • User profiles: Data Analysts, Data Scientists, Data Engineers
  • User assumed knowledge: How to use DocumentDB SDK

Amazon DocumentDB is a fast, reliable, and fully managed database service. Amazon DocumentDB makes it easy to set up, operate, and scale MongoDB-compatible databases in the cloud. With Amazon DocumentDB, the users can run the same application code and use the same drivers and tools that they would with MongoDB. It is a NoSQL database for documents.

Accessing DocumentDB programmatically#

In order to connect your DocumentDB store, you will need the following info:

  • DNS address and port number of DocumentDB
  • User credentials of the database

Additionally, you need to be connected to the EC Dataplatform network. This means you either have to be inside your Amazon Workspace, or be connected with the AWS VPN Client.

  1. If SSL/TLS connections are required for your environment, you need to download the root certificate. This can be downloaded here

  2. Access your MongoDB endpoint, with the received database password and the location of the downloaded .pem file:

    mongodb://masteruser:<insertYourDatabasePassword>@<insertDNS>:27017/?ssl=true&ssl_ca_certs=<location of the downloaded .pem file>&replicaSet=rs0

    If you are in the same folder as the one in which you downloaded the .pem file, you can use:

    mongodb://masteruser:<insertYourDatabasePassword>@<insertDNS>:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0

  3. Use this MongoDB endpoint in your Python code:

import pymongo
import sys
##Create a MongoDB client with the MongoDB endpoint specified in the previous step
client = pymongo.MongoClient(<MongoDB endpoint>) 
##Specify the database to be used
db = client.sample_database
##Specify the collection to be used
col = db.sample_collection
##Insert a single document
col.insert_one({'hello':'Amazon DocumentDB'})
##Find the document that was previously written
x = col.find_one({'hello':'Amazon DocumentDB'})
##Print the result to the screen
print(x)
##Close the connection
client.close()