Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install MongoDB on Rocky Linux and AlmaLinux - DesignLinux

Aug 05 2021
designlinux 0 Comments

MongoDB is a high-performance, highly scalable document-oriented NoSQL database that is designed to handle high traffic and huge volumes of data. Unlike in SQL databases where data is stored in rows and columns inside tables, in MongoDB, data is structured in JSON-like format inside records which are referred to as documents.

Thanks to its schema-less architecture, MongoDB is highly flexible, and provides both horizontal and vertical scaling highly scalable, and makes it possible to only store data that is required as required by an application. At its core.

MongoDB provides the following key features:

  • Rich queries
  • Indexing
  • Replication & high availability
  • Horizontal and vertical scaling
  • Auto sharding
  • Load balancing

MongoDB is a perfect choice in applications that handle high traffic and which need to scale to massive sizes within a short time span. It’s also ideal in iterative development where software development is broken down into smaller manageable chunks.

[ You might also like: 6 Useful Tools to Monitor MongoDB Performance ]

MongoDB is easy to install and is available both on private and public clouds such as AWS and Azure. In this guide, we will install MongoDB on Rocky Linux and AlmaLinux.

Step 1: Add the MongoDB Repository

From the start, we are going to create a repository for MongoDB, as this is because MongoDB packages are not available in Rocky Linux and AlmaLinux AppStream repositories.

So, create the MongoDB repository as follows.

$ sudo vim /etc/yum.repos.d/mongodb-org.repo

Then Paste the following configuration below. This will enable you to install the latest version which, at the time of publication, is MongoDB 4.4.

[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

Once you’ve added the repository, update the system repositories to sync the newly added MongoDB repository with the system.

$ sudo dnf update

Step 2: Install MongoDB on Rocky Linux

Moving on, we are now going to install MongoDB. To do so, we will run the command:

$ sudo dnf install mongodb-org
Install MongoDB on Rocky Linux
Install MongoDB on Rocky Linux

Press 'y' to import the MongoDB GPG key and hit ENTER.

Import MongoDB GPG Key
Import MongoDB GPG Key

Once the installation of MongoDB is complete, verify the version installed as follows.

$ mongod --version

The command provides the version of MongoDB installed among other details such as OpenSSL version and Environment.

Check MongoDB Version
Check MongoDB Version

Step 3: Start and Enable MongoDB

The MongoDB daemon doesn’t start automatically upon installation. You can confirm this by running the command as follows.

$ sudo systemctl status mongod

Before anything else, we need to start the MongoDB daemon and enable it to automatically start on boot time. Therefore, run the commands below sequentially to start and enable MongoDB

$ sudo systemctl start mongod
$ sudo systemctl enable mongod
Start MongoDB Service
Start MongoDB Service

Once again, verify the status of MongoDB, and this time around, MongoDB will be up and running.

$ sudo systemctl status mongod
Check MongoDB Status
Check MongoDB Status

To log into the Mongo shell, run the command:

$ mongo
Start MongoDB Shell
Start MongoDB Shell

Step 4: Using MongoDB to Manage Databases

With MongoDB installed, let’s have a quick run-through of some of the operations on the shell.

To view the databases currently in place, run the command shown. By default, MongoDB provides a test database called test.

> db

To create a database execute the use command followed by the non-existent database name. In this example, we are creating a database called tecmint-db.

> use tecmint-db
Create MongoDB Database
Create MongoDB Database

Now let’s add some data. As earlier discussed, MongoDB stores data in records called documents. The data is in a JSON-like format and entries exist as key-value pairs.

Here, we are have created a document called students and inserted some student data as follows. Paste this on your MongoDB prompt and hit ENTER.

db.students.insertOne(
   { "First Name" : "John",
     "Last_Name"  : "Doe",
     "City" : "Lisbon",
     "Id No." : 34569765,
     "Age" : 28
   }
)

To view the documents in your database, run the command.

> show collections

To display the data stored in the documents run:

> db.students.find()
OR
> db.students.find().pretty()
View MongoDB Database Data
View MongoDB Database Data

To delete the document, the command will be:

> db.students.drop()
Conclusion

MongoDB is a highly scalable and flexible NoSQL database system that is increasingly being adopted by developers due to its versatility and flexible model. It is easy to learn and can be used with major programming languages such as Python and Java. In this guide, we walked you through the installation of MongoDB on Rocky Linux and AlmaLinux.

Related

Tags: AlmaLinux Tips, MongoDB Tips, Rocky Linux Tips

How to Configure Apache Virtual Hosts on Rocky Linux

Prev Post

Secure Apache with Let’s Encrypt Certificate on Rocky Linux

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 255
  • 614,627

DesignLinux.com © All rights reserved

Go to mobile version