How to Install MongoDB in 5 Minutes in Windows OS, Ubuntu OS?

FREE Online Courses: Transform Your Career – Enroll for Free!

Yes, you can install MongoDB on Windows OS or in Ubuntu OS in 5 Minutes. The article is specially designed for the installation process of MongoDB. Moreover, we will discuss how can we start, stop, run, restart and get help in MongoDB software.

So, let’s start the steps to install MongoDB.

How to Install MongoDB on Windows OS?

Now to start the installation on windows, we will have to download MongoDB (latest) from https://www.mongodb.org/downloads. Make sure that you get the correct version corresponding to your Windows version. To get the information about your Windows version follows these simple steps on a command prompt.

C:\>wmic os get osarchitecture

Output – OSArchitecture

64-bit

C:\>

32-bit version supports databases smaller than 2GB and is suitable for evaluation and testing purpose.

Now, we will have to extract our downloaded file to c:\ drive or any other location. Make sure the name is mongodb-win32-i386-[version] or mongodb-win32-x86_64-[version]. Here, [version] denotes the version of MongoDB you have downloaded.

  • Now open the command prompt and run the following command.
C:\>move mongodb-win64-* mongodb

Output –1 dir(s) moved.

C:\>
  • If extracted at some other path then go to the path by using cd FOLDER/DIR and run the above process again.

MongoDB will require data folder to store the files. The default location is c:\data\db.

  • So, now you will have to create the folder by using a command prompt.
C:\>md data

Output – C:\md data\db

If you want to install MongoDB, at a different location, then you need to specify the path for \data\db by setting the path dbpath in mongodb.exe. In command prompt search for bin directory in the installation folder.

  • Suppose you have the installation folder at D:\set up\mongodb.
C:\Users\XYZ>d:
D:\>cd "set up"
D:\set up>cd mongodb
D:\set up\mongodb>cd bin
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"

This will pop up a message “waiting for connections” on the console output, which indicates that mongodb.exe is running successfully.

  • To run MongoDB, you will have to again open the command prompt and type in the following commands.
D:\set up\mongodb\bin>mongo.exe

Output – MongoDB shell version: 2.4.6

connecting to: test

>db.test.save( { a: 1 } )

>db.test.find()

{ “_id” : ObjectId(5879b0f65a56a454), “a” : 1 }

>
  • Next time when you run MongoDB, you need to issue only commands
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
D:\set up\mongodb\bin>mongo.exe

How to Install MongoDB on Ubuntu OS?

To download and install MongoDB on Ubuntu OS, follow these steps:

  • Run the following command
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  • Create a etc/apt/sources.list.d/mongodb.list file using the following command
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen'
| sudo tee /etc/apt/sources.list.d/mongodb.list
  • Now type the following command to check for updates
sudo apt-get update
  • Now, install MongoDB using this command
apt-get install mongodb-10gen = 4.0.5

This is the latest version of MongoDB.

MongoDB Start/ Stop/ Restart/ Run/ Help

i. How to Start MongoDB?

Follow this command-

sudo service mongodb start

ii. How to Stop MongoDB?

Follow this command-

sudo service mongodb stop

iii. How to Re-Start MongoDB?

Follow this command-

sudo service mongodb restart

iv. How to Run MongoDB?

Follow this command-

mongo

This will connect you to running MongoDB instance.

v. How to get Help in MongoDB?

To get a list of useful commands type db.help() in the client side of MongoDB.

How To Get The Statistics From Server Side?

Install MongoDB

Install MongoDB – Statistics from Server Side

Type command db.stats() in the client side to get information about MongoDB server. This tells us about the database name, a number of collections and documents in a database.

Install MongoDB

Install MongoDB – Statistics from Server Side

So, this was all about MongoDB Installation Process. Hope you like our explanation.

Summary of MongoDB Installation Process

Hence, we have seen the MongoDB Installation Process. We have learned to download and configure MongoDB, it on Windows and Ubuntu OS. It was all about setting it up and getting to know about the help list as well as the statistics related to the MongoDB server.

Still, if you have any query, feel free to ask in the comment tab.

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *