HomeBlogsHow to Install MongoDB on Rocky Linux and AlmaLinux

How to Install MongoDB on Rocky Linux and AlmaLinux

This tutorial is about How to Install MongoDB on Rocky Linux and AlmaLinux. We will try our best so that you understand this guide. I hope you like this blog, How to Install MongoDB on Rocky Linux and AlmaLinux. If your answer is yes, please do share after reading this.

So lets keep reading for intertesting info:

Check How to Install MongoDB on Rocky Linux and AlmaLinux

MongoDB is a general-purpose, object-oriented, dynamic NoSQL database server used for developing modern dynamic applications. In MongoDB, data objects are stored as separate documents in a collection, unlike traditional relational databases that use rows and columns. There is both the community version, which is free to download, and the enterprise version, which is part of the Mongo Advanced subscription and has more features, such as LDAP, Kerberos, etc.

MongoDB Compass is the official MongoDB GUI tool that graphically supports creating, reading, updating, and deleting databases. It eliminates the need to run Mongo commands for each task. It allows you to explore data, execute queries and interact with the database with full CRUD functionality.

How to install MongoDB on Rocky Linux and AlmaLinux

Add the MongoDB repository

  • From the beginning, we are going to create a repository for MongoDB, as this is because MongoDB packages are not available in the 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 allow you to install the latest version which, at the time of publishing, 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/
    • gpcheck=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.

Install MongoDB on Rocky Linux

  • Moving on, we are now going to install MongoDB. To do this we will execute the command:
    • $ sudo dnf install mongodb-org
  • Press ‘y’ to import the GPG key from MongoDB and press ENTER.
  • Once the MongoDB installation is complete, check the installed version as follows.
  • The command provides the installed MongoDB version, among other details, such as the OpenSSL version and environment.

Start and enable MongoDB

  • The MongoDB daemon does not start automatically after installation. You can confirm this by running the command as follows.
    • $ sudo systemctl mongod status
  • First of all, we need to start the MongoDB daemon and enable it to start automatically at boot time. So, run the following commands sequentially to start and enable MongoDB
    • $ sudo systemctl start mongod
    • $ sudo systemctl enable mongod
  • Once again check the status of MongoDB and this time MongoDB will be up and running.
    • $ sudo systemctl mongod status
  • To login to the Mongo shell, run the command:

Using MongoDB to manage databases

  • With MongoDB installed, let’s do a quick review of some of the operations in the shell.
  • To see the databases currently in place, run the command shown. By default, MongoDB provides a test database called test.
  • To create a database, run the use command followed by the name of the nonexistent database. In this example, we are creating a database called tecmint-db.
  • Now let’s add some data. As discussed above, MongoDB stores data in records called documents. The data is in a JSON-like format, and the inputs exist as key-value pairs.
  • Here, we have created a document called students and inserted some student data as follows. Paste this into your MongoDB prompt and press ENTER.
    • db.students.insertOne(
    • { “Name”: “xyz”,
    • “Last Name”: “xzy”,
    • “City”: “xzy”,
    • “ID number” : xyz,
    • “Age”: xyz
    • }
    • )
  • To view the documents in your database, run the command.
  • To display the data stored in the documents run:
    • > db.students.find()O
    • > db.students.find().pretty()
  • To delete the document, the command will be:

Final words: How to Install MongoDB on Rocky Linux and AlmaLinux

I hope you understand this article, How to Install MongoDB on Rocky Linux and AlmaLinux. If your answer is no, you can ask anything via the contact forum section related to this article. And if your answer is yes, please share this article with your friends and family to give us your support.

James Hogan
James Hogan is a senior staff writer at Bollyinside, where he has been covering various topics, including laptops, gaming gear, keyboards, storage, and more. During that period, they evaluated hundreds of laptops and thousands of accessories and built a collection of entirely too many mechanical keyboards for their own use.


Must Read

- Advertisment -