Site icon DataFlair

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

How to Install MongoDB

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

FREE Online Courses: Dive into Knowledge for Free. Learn More!

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.

C:\>move mongodb-win64-* mongodb

Output –1 dir(s) moved.

C:\>

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

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.

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.

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 }

>
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:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen'
| sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
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 – 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 – 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.

Exit mobile version