In our code, we are just declaring a simple JavaScript variable to store a string called ‘Hello World’, and for printing the value on the screen we are using the print Json method.
Installing RoboMongo for MongoDB
To write MongoDB commands, we need a tool; therefore, we use RoboMongo. We can also use MongoDB Compass for that, but in this tutorial, we have used RoboMongo.
RoboMongo is free and open-source software that supports all three operating systems: Windows, Linux, and Mac OS. Now, it depends on you which tool you want to use.
Steps to Download and Install RoboMongo
Step 1:
- Go to the link: Download RoboMongo
- Click on the Download Robo 3T button and download the setup depending upon your PC’s architecture. Here, it is the 64-bit version
Step 2:
- In the new window, select your operating system
- Once you select the OS, click on the version (i.e., 64-bit version)
Step 3:
- You have downloaded the setup. Now, click on the .exe file
- Click on Next
Step 4:
- In the new window, click on I Agree for accepting the license agreement’s terms and conditions
Step 5:
- Click on Install and the installation process starts
Step 6:
- In the new window, you need to create your new connection, but before that go to the Command Prompt and write mongod to start MongoDB
Step 7:
- Later on, press on Create
- In the pop-up window, name your connection
- Click on Save and then on Connect
Step 8:
- Once the connection is created, right-click on it and open the new shell. Now, you are ready to write your database query
So far, we have learned the steps to download and install MongoDB. Now, we will move ahead with the most important topics, i.e., various queries in MongoDB and how to write and execute them.
MongoDB installation on Linux
The installation packages of 64 and 32 bits are available on the web for Linux. In order to install the tool, you need to download a suitable package.
Step 1:
- Download the package: Download the MongoDB packages from the following link: http://www.mongodb.org/downloads
Step 2:
- Unzip the folder: Unzip the downloaded folder at the location where you would like to install the tool
Step 3:
- Create a data directory: Create a data directory manually in the root as the data is stored in this directory only
Step 4:
- Run MongoDB server: Run the MongoDB server on the command prompt for which you need to execute the mongod.exe file from the bin folder inside the MongoDB folder
Step 5:
- Start Administrative Shell: Specify the bin directory location of the MongoDB package and run mongo.exe file. The administrative shell is a JavaScript shell and the moment you install MongoDB, it will connect you to the test document.
Concluding this tutorial, so far, we have learned how to download and install MongoDB, and then we saw how to download Robo 3T and install it for writing the MongoDB commands. I hope this tutorial has helped you clear all the doubts that arise when you start learning MongoDB so that you can choose the right career path.