W3Schools Learner's Blog

W3Schools Programming knowledge summary website



How To Install MongoDB on CentOS 7

How To Install MongoDB on CentOS 7


MongoDB is a document-oriented database that is free and open-source. 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. You can alter the schema at any time and as often as is necessary without having to setup a new database with an updated schema.
This tutorial guides you through installing MongoDB Community Edition on a CentOS 7 server.


Before following this tutorial, make sure you have a regular, non-root user with sudo privileges. You can learn more about how to set up a user with these privileges from our guide, How To Create a Sudo User on CentOS.

Step 1 – Adding the MongoDB Repository

The mongodb-org package does not exist within the default repositories for CentOS. However, MongoDB maintains a dedicated repository. Let's add it to our server.
With the vi editor, create a .repo file for yum, the package management utility for CentOS 7:
  1. sudo vi /etc/yum.repos.d/mongodb-org.repo
Then, visit the Install on Red Hat section of MongoDB’s documentation and add the repository information for the latest stable release to the file:
  1. [mongodb-org-3.4]
  2. name=MongoDB Repository
  3. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
  4. gpgcheck=1
  5. enabled=1
  6. gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Save and close the file.
Before we move on, we should verify that the MongoDB repository exists within the yum utility. The repolist command displays a list of enabled repositories:
  1. yum repolist


  1. Output
  2. . . .
  3. repo id                          repo name
  4. base/7/x86_64                    CentOS-7 - Base
  5. extras/7/x86_64                  CentOS-7 - Extras
  6. mongodb-org-3.2/7/x86_64         MongoDB Repository
  7. updates/7/x86_64                 CentOS-7 - Updates
With the MongoDB Repository in place, let's proceed with the installation.

Step 2 – Installing MongoDB

We can install the mongodb-org package from the third-party repository using the yum utility.
  1. sudo yum install mongodb-org
There are two Is this ok [y/N]: prompts. The first one permits the installation of the MongoDB packages and the second one imports a GPG key. The publisher of MongoDB signs their software and yum uses a key to confirm the integrity of the downloaded packages. At each prompt, type Y and then press the ENTER key.
Next, start the MongoDB service with the systemctl utility:
  1. sudo systemctl start mongod
Although we will not use them in this tutorial, you can also change the state of the MongoDB service with the reload and stop commands.
The reload command requests that the mongod process reads the configuration file, /etc/mongod.conf, and applies any changes without requiring a restart.

Syntax of update method of SimpleJdbcTemplate class

  1. sudo systemctl reload mongod
The stop command halts all running mongod processes.
  1. sudo systemctl stop mongod
The systemctl utility did not provide a result after executing the start command, but we can check that the service started by viewing the end of the mongod.log file with the tail command:

  1. sudo tail /var/log/mongodb/mongod.log


  1. Output
  2. . . .
  3. [initandlisten] waiting for connections on port 27017

No comments:

Post a Comment

Note: only a member of this blog may post a comment.