Skip to content

Setting up a free tier mongo db cluster

Siddhartha Anand edited this page Nov 4, 2018 · 1 revision

We are going to learn the following by the time we reach the end of this page:

  • Set up a free-tier mongo cloud account

  • Set up a user to provide access with.

  • Try out a few commands using the mongo-db shell.

  • Following the awesome documentation of mongo-db, I opened a free-tier mongo-db account to experiment with the usages of the mongo-db functionality.

  • You need to set up your account using your credentials, and then on the next page you come across the configuration of the cluster. You can customise it with the available options.

  • Since, I did not want to pay anything for trying out mongo-db, I opted for the default version i.e. the free M0 cluster which is a shared cluster. By shared, I presume, the cluster hardware which would be shared by other clusters too which would not be specific to my application.

  • You can also set your cluster name at the end of the configuration page.

  • Quickly, you can finish this up and proceed forward.

Creating a Sandbox for experimenting with mongo-db

  • After I created a free account, it took a few minutes to provision the aforementioned cluster.

  • Now, I added users which can remotely use the database. It is a necessary step so that at the least, one user is able to connect to the database. Here you can add the list of users who you want to let access to the database. You can also define their Roles so that their accessibility is limited to their Roles. For example, I added myself as the owner admin of the clusters.

  • The next step is to get a mongo-db shell so that you can use your shell to connect to the database and run CRUD commands to try it out!

  • You can open the shell and try out a few commands:

use test

This will create a database named db if not already present. If it is present, then it will switch to that database.

db.testCollection.insertOne({x:1})

This will insert one document {x:1} to the testCollection named Collections. It will create a collection named testCollection if not already present in test database. This command helps you in doing so. You will get an acknowledgement from the database server similar to the following:

{
	"acknowledged" : true,
	"insertedId" : ObjectId("5beeb324a260f3ec44990dc1")
}

This means your document has been inserted into the test database. 👍

db.testCollection.find()

This command returns all the documents inserted into the test database. The output will be similar to the following:

{ "_id" : ObjectId("5beeb324a260f3ec44990dc1"), "x" : 1 }

mongo, by default, associates an "_id" attribute with every document inserted into the collection.

  • You might have noticed that the database name is test, but I have used db to refer to the test database. It seems that mongo automatically assigns the variable db to point to the test database. The documentation does not mention this, but it seems to be working fine 👍