MongoDB offers data aggregation as it allows us to store data according to our preferences. Otherwise, we have to manage data according to the data management of a conventional database. This article will help us to understand how to install MongoDB in Ubuntu 20.04.

Prerequisites

You must have shell access to the Ubuntu system with sudo privileged account.

Installing MongoDB on Ubuntu

  1. Open the terminal and add the repository key of MongoDB to the apt keyring. We can do this by following commands. It will ask for a password:
  2. Now, we will add the MangoDB repository to our repository list by editing in the system’s list of sources. To access the editor of the system’s list we open the source list: Add the following line in the file as shown in the image: Press CTRL + O to save changes and CTRL + X to exit from the editor.
  3. Update the apt repository and then install the Mongodb server packages. This will install the MongoDB server on your system along with the required dependencies.
  4. Now, start the MongoDB daemon using the systemctl utility. Also, enable the service to auto-start on system reboot.
  5. Once the service started successfully, check the service status by typing the following command.
  6. Type “mongo” command on terminal and run to connect to the mongo shell: That’s it, the MongoDB server is up and running on your system.

Enable Authorization in MongoDB

By default, anyone can access MongoDB and can make changes to it. To secure it we will enable user authentication on the MongoDB server. This will prevent anonymous access to the database server. Login to the Mongo shell: We will type “use admin” in the mongo shell so now we are in its administration section. Next, create a user account with admin privileges in MongoDB. Now exit the editor by pressing CTRL + C. Next we need to enable security in MongoDB configuration file. Edit the mongo configuration file by using: The setting will be open and go to the “#security” section. Remove the “ # ” and type “authorization: enabled”. Now exit by pressing CTRL + x, type “ y ” and press ENTER to exit by saving the file. Now restart the MongoDb and then check its status: Now the database is secured, only admin users can access it by entering the set password. Use the following command to connect to the MongoDB server.

Conclusion

If we are doing a startup project and you know you have to make a lot of changes then MongoDB is the best database to work with as compared to conventional databases. In this article, we learned about MongoDB and how we can install and secure MongoDB on Ubuntu 20.04.

How To Install and Secure MongoDB on Ubuntu 20 04   TecAdmin - 2How To Install and Secure MongoDB on Ubuntu 20 04   TecAdmin - 58How To Install and Secure MongoDB on Ubuntu 20 04   TecAdmin - 48