Advance

Tutorial Setup and Use MongoDB on Rocky Linux

Tutorial Setup and Use MongoDB on Rocky Linux
0
(0)

Programmers use different databases in web and application development. Databases based on SQL or NoSQL have different applications according to system requirements and programmers’ preferences. In this article, we intend to teach you How to Setup and Use MongoDB on Rocky Linux. If you want to buy Linux VPS server, you can visit the packages offered on the Eldernode website.

1 Way to Setup MongoDB on Rocky Linux

Recommended Article: How to install Fail2Ban to protect SSH on CentOS 8

Introduction to MongoDB and its Features

MongoDB is one of the most famous No SQL databases, which has a flexible structure and is mostly used in projects with a large amount of data. This database is a free and open-source platform that works with a Document-Oriented data model and can be used on Windows, Macintosh, and Linux. Data values stored in MongoDB are used with two primary keys and secondary keys.

MongoDB contains an array of values. These values are in the form of documents that contain different types of data with different sizes. This issue has made MongoDB able to store data with a complex structure such as hierarchical or array data.

Some of the features of MongoDB are:

– MongoDB is much more flexible and scalable compared to relational databases due to its document-oriented data storage model, and it solves many business needs.

– This database uses sharding to divide data and manage the system better.

– The data can be accessed with two primary and secondary keys, and each field can be keyed. This makes data access and processing time very fast.

– Replication is another important feature of MongoDB. d

How to Install MongoDB on Rocky Linux

After getting acquainted with MongoDB and its features in the previous section, now in this section we are going to teach how to install it on Rocky Linux. To do this, just follow the steps below in order. In the first step, you must update the system by running the following command:

sudo dnf update -y

Then you need to add the MongoDB repository using the following command:

cat > /etc/yum.repos.d/mongodb.repo << 'EOL'  [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  EOL

Now it’s time to install the community version of MongoDB by running the following commands:

sudo dnf install mongodb-org -y

Start and enable MongoDB by running the following commands:

systemctl start mongod
systemctl enable mongod

Note that you can check the installation status of MongoDB by running the following command:

mongod --version

How to Use MongoDB on Rocky Linux

In the previous section, you learned how to install MongoDB on Rocky Linux. In the following, we will teach you how to implement and use it. You can check the log file for any errors by running the following command:

tail /var/log/mongodb/mongod.log

If there is no error, you can access the MongoDB shell by running the following command:

mongo

To view the databases available in your system, run the following command:

db

How to Create a New Database and User

Here to create a new MongoDB database, you need to change 0 to the new database. Note that we will create a database named elder-db:

use elder-db

Now you can insert a set of documents (data structure in MongoDB) into your new database by running the following command. Then, press Enter:

db.linux.insertOne(  {"Rocky Linux" : "8",  "ubuntu" : "20.04",  "centos" : "8",  "debian" : "10"  }  )

Now you can use the following command to display the documents in the database:

show collections

You can also use the following command to display the content of the database:

db.linux.find()

To create a user as admin with read/write privilege, you can use the following command. Then, press Enter:

db.createUser(  {  user: 'admin ',  pwd: '$trongP@ssWord',  roles: [ { role: 'readWrite', db: 'elder-db' } ]  }  );

If you want to see the list of users, run the following command:

db.getUsers()

Finally, to exit MongoDB, you must run the following command:

exit
Recommended Article: How to setup IKev2 on centos 8 complete

Conclusion

MongoDB and in general NoSQL databases are very flexible to accept data of different types and this is an important advantage for programmers. The scalability of this database allows it to be used in projects that deal with Big Data. In this article, we tried to teach you How to Setup and Use MongoDB on Rocky Linux. If you have any questions, you can share them with us in the comments section.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day