What is MongoDB Atlas
MongoDB Atlas is the global cloud database service for modern applications, or in another word, it’s MongoDB in cloud. Instead of setting up your mongodb database in your local/remote server, MongoDB Atlas allows an easy and quick connection to your Node.js application with a single line of mongooes (mongodb driver).
What I am trying to develop
A survey app to help estimate household water usage:
The reason I choose MongoDB instead of MySQL
First of all, with Node.js + Express as framework, it’s easier to utilize the native js object in text form: JSON, and that’s one of the reason that MongoDB is in the starter pack of MERN Development (Yes, the M in “MERN” stands for MongoDB instead of MySQL).
As the website assess user through each question, front end pages was rendered with each question set, or in other word, each js object:
Another reason that you should choose MongoDB is that it lets developer to access, manage, and use their data in an “object-oriented” way instead of struggling with tables and keys in a traditional relational database, even it usually comes with the tradeoff of query efficiency.
How to set up MongoDB and the Mongo shell
Before starting with MongoDB Atlas, Let’s see how we can install MongoDB in our local environment.
First of all, download the community version from:
Download Center: Community Server
Download MongoDB Community Server, the most popular non-relational database built to address the needs of modern…
When the database is installed, you will have two options to interact with it:
Mongo Shell or MongoDB Compass
But before that, you will need to configure a little bit so your local terminal knows how to find and start the MongoDB
cd // go to your root directorytouch .bash_profile // create a profile file
Then all you need to do is copy the path of your MongoDB directory into the file you just created.
alias mongod="/c/Program\ files/MongoDB/Server/4.2/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.2/bin/mongo.exe"
After that, you should be able to start MongoDB in your environment with “mongod” command:
As the database is already up and running, try open another terminal and enter “mongo”:
Congratulations, You can start playing with mongo shell now!
How to use MongoDB Compass to manage your remote connection
Similiar to MySQL workbench, MongoDB offers a more friendly interface than mongo shell to users to mange their databases, collections, and documents, which is the MongoDB Compass:
I’m not going to waste your time on explaining how to use it, but instead, let’s see how we can use it to manage a remote cluster in MongoDB Atlas.
MongDB Atlas is a remote database service that allows user to deploy their database on a cloud server, this means you don’t really need a local database anymore and Atlas will be dealing with your data on the server you choose.
First, go to MongoDB Atlas website and start a cluster.
After that, register yourself as a new admin:
Then, go to the network access section and setup the whitelist.
Go back to your clusters dashboard, and now you can use the connection string to access the Atlas cluster with either shell or Compass.