On this article we will learn how to install MongoDB Community Edition on CentOS 8. MongoDB is a free and open-source document database. Data is stored as JSON-like documents and classified as NoSQL database like Apache CouchDB.
Introduction
MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL). MongoDB offers both an Enterprise and Community version of its powerful distributed document database. The latest version of MongoDB when this article is written is version 4.4. MongoDB is available on Cloud and downloadable source. On this article, we will discuss how to deploy MongoDB Community Edition on CentOS 8.
MongoDB installation on CentOS 8
MongoDB only supports the 64-bit versions of these platforms. The installation process will be consist of several task, as described below :
- Prerequisite
- Configure the package management system (yum).
- Install the MongoDB packages.
- Enable and Startup the MongoDB Services
- Testing MongoDB
Prerequisite
Before we are deploying MongoDB on CentOS 8 operating system, we have to fulfill the prerequisite first. As described on the MongoDB documentation, if MongoDB only supports the 64-bit versions of these platforms.
- CentOS 8 system with sufficient space
- Account user with sudo privilege or root account
Configure Package Management System
At this step, we will create repository file for MongoDB. The file name and location is /etc/yum.repos.d/mongodb-org-4.4.repo
.
[ramans@otodiginet ~]$ sudo vi /etc/yum.repos.d/mongodb-org-4.4.repo
Then paste, the entries below :
[mongodb-org-4.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

Install the MongoDB packages
After MongoDB repository was added to the system, the next step is jus install it. To install the latest stable version of MongoDB, issue the following command: sudo dnf install -y mongodb-org
.
[ramans@otodiginet ~]$ sudo dnf install -y mongodb-org [sudo] password for ramans: MongoDB Repository 4.0 kB/s | 2.5 kB 00:00 Dependencies resolved. Package Architecture Version Repository Size Installing: mongodb-org x86_64 4.4.1-1.el8 mongodb-org-4.4 10 k Installing dependencies: mongodb-database-tools x86_64 100.2.0-1 mongodb-org-4.4 55 M mongodb-org-database-tools-extra x86_64 4.4.1-1.el8 mongodb-org-4.4 20 k mongodb-org-mongos x86_64 4.4.1-1.el8 mongodb-org-4.4 22 M mongodb-org-server x86_64 4.4.1-1.el8 mongodb-org-4.4 28 M mongodb-org-shell x86_64 4.4.1-1.el8 mongodb-org-4.4 18 M mongodb-org-tools x86_64 4.4.1-1.el8 mongodb-org-4.4 10 k

The output will be :

Enable and Startup the MongoDB Services
The next step after installation is starting and enabling MongoDB services. By issuing the following command:
[ramans@otodiginet ~]$ sudo systemctl start mongod [sudo] password for ramans: [ramans@otodiginet ~]$ sudo systemctl enable mongod
Then we verify, if the MongoDB service is already running properly by submitting command line : sudo systemctl status mongod
.
[ramans@otodiginet ~]$ sudo systemctl status mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2020-10-21 10:23:57 PDT; 41s ago Docs: https://docs.mongodb.org/manual Main PID: 56528 (mongod) Memory: 106.6M CGroup: /system.slice/mongod.service └─56528 /usr/bin/mongod -f /etc/mongod.conf Oct 21 10:23:55 otodiginet systemd[1]: Starting MongoDB Database Server… Oct 21 10:23:56 otodiginet mongod[56526]: about to fork child process, waiting until server is ready for > Oct 21 10:23:56 otodiginet mongod[56526]: forked process: 56528 Oct 21 10:23:57 otodiginet mongod[56526]: child process started successfully, parent exiting Oct 21 10:23:57 otodiginet systemd[1]: Started MongoDB Database Server.

Testing MongoDB
In this step, we will use MongoDB, by login to and creating user on its database. To use MongoDB on ist console, just submitting command line : mongo, as described below :
1. Login to MongoDB console
[ramans@otodiginet ~]$ mongo MongoDB shell version v4.4.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("0f6b8954-1c73-48ec-bb8a-142f97110631") } MongoDB server version: 4.4.1 Welcome to the MongoDB shell.

2. Swith Login to ‘admin’
> use admin switched to db admin
3. Create new database user ‘digimbadmin
‘ with role as user Admin for any database and password
‘passwordkoe
‘
db.createUser( … { … user: "digimbadmin", … pwd: "passwordkoe", … roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] … } … ) Successfully added user: { "user" : "digimbadmin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }

4. Show the user that was created.
> show users { "_id" : "admin.digimbadmin", "userId" : UUID("d7db8732-8169-472c-a7ef-0b7f50f66d2b"), "user" : "digimbadmin", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }

Conclussion
We have learnt how to install MongoDB Community Edition version 4.4 (so far the latest version) on CentOS 8. This article is very simple, only a little step for knowing one of the famous NoSQL database, MongoDB.