AWS DocumentDB
Credits Educative.io
AWS DocumentDB creates a MongoDB database cluster, and we’ll store some data in it. We can also create a snapshot and create a new cluster from it.
Some key points:
- we need to create a DocumentDB cluster. There are two types of clusters using DocumentDB (Instance-based clusters and Elastic clusters). Instance-based clusters are used when we’re working with applications that have predictable and consistent data and number of instances is fixed. Elastic clusters are used when we’re working with applications that have unpredictable data and scaling is managed by AWS.
- we need to create a security group, and add inbound rule, “Custom TCP”, “Port range” to 27017 (this is the default port through which our DocumentDB cluster communicates), and add security group associated with our Cloud9 environment from the drop-down list available (this security group will look like aws-cloud9-DocDBEnv-… | sgxxxxxxxxx.).
- we can then install MongoDB shell on our Cloud9 environment, and connect to our DocumentDB cluster using the following command:
- echo -e “[mongodb-org-4.0] =MongoDB Repository=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/ =https://www.mongodb.org/static/pgp/server-4.0.asc” | sudo tee /etc/yum.repos.d/mongodb-org-4.0.repo &&/ sudo yum install -y mongodb-org-shell
- wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
- mongo –ssl –host docdb-2024-01-13-00-57-19.cluster-cinfonv7x3oh.us-east-1.docdb.amazonaws.com:27017 –sslCAFile global-bundle.pem –username educative –password XYZ
MongoDB shell has it’s own language, and we can run commands like show dbs, db.createCollection(“users”), db.users.insert({name: “John”}), db.users.find(), etc. For example, to insert a row into a mp3players collection, we can run the following command:
db.mp3playlist.insertMany([
{id: 1,
"Song 2",
title: "Blur",
artist: "5:47",
duration: "Blur"
album:
}
])
"artist": "XYZ" }) db.mp3playlist.find({