MongoDB is one of the famous , free & open source document oriented No-SQL database server. MongoDB uses JSON like document format to store data in database, rather than using rows & columns, as used in SQL databases like MS-SQL, mysql etc.

When compared with SQL databases or relational databases, MongoDB are far more faster, provide far better performance, are easy to scale & address several shortcomings of any relational database available. MongoDB can handle large amounts of structured or unstructured data or can even support multiple data structures. No-SQL databases, especially MongoDB are the kind of databases that are required to address the needs of data being used today, whether you need databases for IOT or online gaming or for big data, MongoDB will be a right fit.

In this tutorial, we will be learn MongoDB installation for community edition (Enterprise version costs money ) on RHEL/CentOS 7, we have tested this method to be working on Centos 7 & same should work on RHEL 7 or earlier versions of OS as well. Remember one thing, MongoDB does not support RHEL 5 or earlier versions, also latest versions of MongoDB does not support 32 Bit system as well.

( Recommended Read : Installing & configuring MariaDB on RHEL/CentOS )

Adding repository for MongoDB

At the time of writing this tutorial, 3.4 is the latest version of MongoDB & we will be installing same on our system. For MongoDB installation, we will first create a yum repo file for the official MongoDB repository. So firstly create a file, mongodb-org-3.4.repo in /etc/yum.repos.d,

$ vi /etc/yum.repos.d/mongodb-org-3.4.repo

& add the following repository information,

name=MongoDB Repository

now save the file & exit. If you are performing installation on earlier versions of RHEL/Centos (mostly version prior to 6.5) than you might want to install earlier versions of MongoDb, as latest one might not work for you. For earlier versions, just replace 3.4 with earlier version i.e.

$ vi /etc/yum.repos.d/mongodb-org-2.6.repo

name=MongoDB 2.6 Repository

Now that we have our repository ready, we can install MongoDB on our server.

Note :- Odd numbered versions of MongoDB are meant for development & should not be used in production environment.


MongoDB Installation

To install mongodb on server, execute the following command from terminal

$ yum install mongodb-org

This will install mongodb on our server. Once installed, we need to start the service & enable it start after boot,

$ systemctl start mongod

$ systemctl enable mongod


Testing MongoDB

To connect to mongodb after its service has been started, open terminal & type

$ mongo

Once logged in, we can see all the availabe databases by using

$ show dbs

To create a new database or to use an already created database, issue command

$ use database

Though this command will create a database but it will not save the database until some data has been added to it. We will now add a collection named 'inventory' in the database & to do that command is

$ ( { inventory : “Desktops” } )

After the collection has been added , database will be automatically saved & we can verify it by executing command “show dbs”. This completes our tutorial on Mongodb installation, if you have any suggestion or query, please do tell us using the comment box below.

( Recommended Read : MariaDB administration commands for beginners )


If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Become a Supporter - Donate us some of you hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.