MongoDB is a free open source document database. It belongs to a family of databases called NoSQL, which is different from traditional table-based SQL databases such as MySQL and PostgreSQL.
In MongoDB, data is stored in flexible JSON-like documents, with fields varying with the document. It does not require a predefined schema and the data structure can change over time.
This tutorial describes how to install and configure MongoDB Community Edition on CentOS 8 server.
MongoDB is not available in the CentOS 8 core repository. We will enable the official MongoDB repository and install the package.
At the time of this writing, the latest version of MongoDB available from the official MongoDB repository is version 4.2. Before starting the installation, please visit the MongoDB documentation at Installing on Red Hat section of the MongoDB documentation and check to see if a new version is available.
Perform the following steps to install MongoDB on a CentOS 8 system as the root user or as a user with sudo privileges.
Enable the MongoDB repository by creating a new repository file named
mongodb-org.repo in the
mongodb-org metadata package.
During the installation process, you will be prompted to import the MongoDB GPG key. Type
y and click
The following packages will be installed on your system as part of the
mongoddaemon and the corresponding initialization scripts and configuration.
mongodb-org-tools- Contains several MongoDB tools for importing and exporting data, statistics, and other programs.
After installation is complete, enable and start the MongoDB service at.
To verify the installation, connect to the MongoDB database server and print the server version.
Run the following command to display the MongoDB version.
The output looks like this.
The MongoDB configuration file is named
mongod.conf and is located in the
/etc directory. The file is in YAML format.
In most cases, the default configuration settings will be sufficient. However, for production environments, we recommend uncommenting the security section and enabling authorization, as follows.
authorization option enables Role-Based Access Control (RBAC), which manages user access to database resources and operations. If this option is disabled, each user will have access to any database and perform any operation.
After changing the MongoDB configuration file, restart the mongod service.
For more information on MongoDB configuration options, visit the Profile Options documentation page.
Creating a MongoDB administrative user
If MongoDB authentication is enabled, you need to create an administrative user that can access and manage your MongoDB instance.
First, access the MongoDB Shell using the following command.
Type the following command to connect to the
userAdminAnyDatabase role to create a new user named
You can name MongoDB administrative users as needed.
To exit the mongo shell.
To test the changes, access the mongo shell using the administrative user you created earlier.
Now, print the user with the following command.
We have shown you how to install and configure MongoDB 4.2 on CentOS 8 server.
Please check the MongoDB 4.2 manual for more information on this topic.