How to install MongoDB on CentOS

In this article, we will see how to install MongoDB enterprise edition on CentOS operating system.

MongoDB is open source and document oriented database. It is classified as a NoSQL database because it does not rely on a traditional table-based relational database structure. Instead, it uses JSON-like documents with dynamic schemas. Unlike relational databases, MongoDB does not require a predefined schema before you add data to a database.

We are going to perform below steps in this article:

1). Adding the MongoDB Repository
2). Installing MongoDB
3). Start and Connect to MongoDB server
4). Create a database in MongoDB server

Install MongoDB on CentOS step by step:

1. Create an /etc/yum.repos.d/mongodb-enterprise-4.4.repo file so that we can install MongoDB enterprise directly using yum.

touch /etc/yum.repos.d/mongodb-enterprise-4.4.repo

2. Add following lines to the above file mongodb-enterprise-4.4.repo

[mongodb-enterprise-4.4] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.4/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

How to install MongoDB on CentOS

3. Install the MongoDB Enterprise packages by running below command.

sudo yum install -y mongodb-enterprise

Start MongoDB on CentOS:

1. Enable the mongod service.

sudo systemctl enable mongod

2. Check the mongod service status.

sudo systemctl status mongod

3. Start the mongodb server.

sudo systemctl start mongod

Now check the MongoDB server status:

sudo systemctl status mongod

4. Stop the mongodb server.

sudo systemctl stop mongod

5. Restart the mongodb server.

sudo systemctl restart mongod