
Learn about installing and using PostgreSQL on CentOS 8 with this step-by-step guide and take your data management to the next level! Table of Contents
As a Linux professional, mastering how to install and configure MongoDB will empower you to leverage the full power of this popular NoSQL database for efficient and scalable data management.
MongoDB is a popular NoSQL document-oriented database that is known for its high performance, scalability, and flexibility. It was first released in 2009 by the MongoDB company and has since become a widely-used database among developers and enterprises. In this article, we will provide a step-by-step guide on how to install and configure MongoDB on RHEL9/CentOS9.
MongoDB is a NoSQL database that is designed to handle large volumes of unstructured and structured data. Unlike traditional relational databases, which use a fixed schema, MongoDB uses a dynamic schema, which allows for greater flexibility when storing data. MongoDB is also highly scalable, allowing you to add more nodes to a cluster as your data grows, and it provides high availability through replication.
MongoDB’s most popular features include:
|
|
|
|
|
๐ข Step1: MongoDB Repositoryย |
To install MongoDB on RHEL9/CentOS9, you need to add the MongoDB repository to your system. Completing the following steps:
โถ๏ธ Export variables |
There areย several versionsย of MongoDB to choose from. You can specify which version you’d like to install by using the export command:
export MONGODB_VERSION=4.4
export RHEL_VERSION=9
Photo by admingeek from Infotechys
Import the appropriate GPG key for the version of MongoDB installed:
sudo rpm --import https://pgp.mongodb.com/server-$MONGODB_VERSION.asc
In this example, we’re installing MongoDB version 4.4 on a RHEL 9 server. The command below adds the appropriate repository, using the variables we’ve previously defined.
sudo dnf config-manager --add-repo=https://repo.mongodb.org/yum/redhat/${RHEL_VERSION}/mongodb-org/${MONGODB_VERSION}/x86_64
Adding repo from: https://repo.mongodb.org/yum/redhat/9/mongodb-org/4.4/x86_64
๐ข Step 2: Install MongoDB |
Once the repository has been successfully configured, run the command below to install MongoDB:
sudo dnf install mongodb-org
๐ข Step 3: Start and Enable MongoDB |
After installing MongoDB, start and enable the MongoDB service using the following command:
sudo systemctl enable --now mongod
๐ข Step 4: Verify the Installation |
To verify that MongoDB is installed correctly, you can run the following command to check if the service is running:
$ sudo systemctl status mongod
Or, verify the version:
$ mongo
you should see output similar to:
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("adcec2f0-d6c7-4cf7-ac11-0f3bbea4d1a9") }
MongoDB server version: 4.4.6
To create a new database, you can use the following command:
$ use mydatabase
This will create a new database called “mydatabase”.
To create a new collection in MongoDB, you can use the following command:
$ db.createCollection("mycollection")
This will create a new collection called “mycollection” in the current database.
To insert data into a collection, you can use the following command:
$ db.mycollection.insertOne({"name": "John", "age": 30})
This will insert a new document into the “mycollection” collection with the fields “name” and “age”.
To retrieve data from a collection, you can use the following command:
$ db.mycollection.find()
This will retrieve all the documents in the “mycollection” collection.
Here are some best practices for working with MongoDB:
|
|
|
|
|
|
|
|
By following these best practices, you can ensure that your MongoDB database is running efficiently and effectively, and that you are getting the most out of this powerful NoSQL database.
In this article, we have provided a step-by-step guide on how to install and configure MongoDB on RHEL9/CentOS9. We also discussed some of MongoDB’s most popular features and provided some basic usage examples. By following the steps outlined in this article, you can get started with using MongoDB on RHEL9/CentOS9 and take advantage of its high performance, scalability, and flexibility.
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.

Learn about installing and using PostgreSQL on CentOS 8 with this step-by-step guide and take your data management to the next level! Table of Contents

Are you looking to improve your database management skills? Learn how to install and configure Cassandra, the highly scalable NoSQL database, and take your career

Unlock the power of relational databases and streamline your data management processes by discovering how to easily install MySQL on CentOS – a must-know skill
