Unlike relational databases, it is free from the tables, you can add and modify the data easily due to its document-oriented data model and because of this model, it can correspond to different data types of many programming languages.
MongoDB has some distinctive features like it is schema-less so you are free from the burden of type-mapping, similarly, it can be used as a file system with data replication and load balancing features over multiple machines for storing files.
In this writeup, we will discuss the method to install MongoDB on Debian 11.
How to install MongoDB on Debian 11
For the installation of the latest version of MongoDB on Debian, first, we will install the “wget” package. This package is used to import the GPG key of MongoDB.
We will import the GPG key of MongoDB from its official website.
The output of the executed command should be “OK”. There is a warning that the key we are going to be added is deprecated but we can still use it. Enable the MongoDB repository by creating a file /etc/apt/sources.list.d/mongodb-org-5.0.list and as the “bullseye” version of MongoDB is still not released so we use the “buster” version of MongoDB.
Update the repository.
Now we will install the MongoDB package along with other packages which are related to MongoDB.
After the successful installation of MongoDB, start it using the systemctl command.
Once the MongoDB is started, enable it as
Check the status of MongoDB and verify it is running successfully.
To check the version of MongoDB which is installed.
To secure the MongoDB, launch the MongoDB.
Type the “admin” in the environment of MongoDB.
You will be switched to the DB main. Write the following command to add a user to create user, username is “mongoAdmin” and password is “abc123”, you can change username and password accordingly:
{
user: “mongoAdmin”,
pwd: “abc123”,
Roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]
}
)
The output shows the user is added successfully. Once done type “quit()” to exit the MongoDB environment.
To enable the security of MongoDB, open the configuration file of MongoDB.
Find out the “Security”, uncomment it by removing “#” and write a line next to it.
Save it by pressing CTRL + S and then exit by pressing CTRL + X. Restart the MongoDB so it can refresh the modified changes:
To verify that the user has been added we will run the following command, change “mongoAdmin” in the command by your username, and after execution, it will ask for a password, enter the password which in our case is “abc123”.
Type the “use admin”, once you are in the MongoDB environment.
To display the users type “show users”:
We can see the user has been displayed which we created.
Conclusion
MongoDB is easy to use if you are familiar with JavaScript. Also, it is schemaless. Other than that, it is recommended to beginners due to its ease of use and efficiency. In this write-up, we have discussed the installation procedure of MongoDB, by importing its key to the repository of Debian and then installing it. Confirm its status after starting and enabling it, and then add a user to MongoDB by assigning it a role.