• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install MongoDB on Debian 11 Linux

Written by Admin, Updated On January 11, 2023
database, debian, mongodb
How to Install Mongodb on Debian 11

MongoDB is an open-source, cross-platform NoSQL database server. It uses JSON document to store data and fields can be vary from compare to other. In this tutorial, we will explain how to install latest version of MongoDB Community Edition on Debian 11 Bullseye.

MongoDB is popular for handling large amounts of data due to its performance, scalability and high availability. It doesn’t require a predefined schema or data structure, it might be different. It is different from the traditional table-based SQL databases like MySQL and PostgreSQL. For more details check official installation page of MongoDB’s documentation.

Perform the following steps to install MongoDB on Debian 11 with root or user with sudo privileges.

Step 1 – Install MongoDB#

MongoDB is not available in the default Debian Bullseye repositories. We need to enable manually the official MongoDB repository and then install the packages.

First of all, install additional packages which are require, run following command:

sudo apt install dirmngr gnupg apt-transport-https software-properties-common ca-certificates curl

At first, you need to add the MongoDB GPG key to your system using curl:

curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

After that enable the MongoDB repository:

sudo add-apt-repository 'deb https://repo.mongodb.org/apt/debian buster/mongodb-org/6.0 main'

Now, update the packages list and install mongodb-org meta-package:

sudo apt update
sudo apt install mongodb-org

Below packages will be installed on the system as a part of the mongodb-org package:

  • mongodb-org-server – The mongod daemon and corresponding init scripts and configurations.
  • mongodb-org-mongos – The mongos daemon.
  • mongodb-org-shell – The mongo shell is an interactive JavaScript interface to MongoDB. It is used to perform administrative tasks through the command line.
  • mongodb-org-tools – Contains several MongoDB tools for importing and exporting data, statistics, as well as other utilities.

You should start the MongoDB service and enable it for start on boot:

sudo systemctl enable mongod --now

Now, it’s time to verify that installation is completed successfully. Login to mongo tool and print connection status:

mongo
mongo --eval 'db.runCommand({ connectionStatus: 1 })'

It should look like this:

MongoDB shell version v6.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5ef18h52-802j-99fg-cvjf-b6b06e801bc5") }
MongoDB server version: 6.0
{
	"authInfo" : {
		"authenticatedUsers" : [ ],
		"authenticatedUserRoles" : [ ]
	},
	"ok" : 1
}

If in ok field value is 1 then it indicates success.

Step – 2 Configuring MongoDB#

Generally, default configuration settings are enough for most users. But it’s advised to change few settings for production environment, specially security section. The MongoDB configuration file mongod.conf is located in the /etc directory. Edit the mongod.conf file and uncomment the security section and enable authorization:

security:
   authorization: enabled

It will enables Role-Based Access Control (RBAC) that regulates users access to database resources and operations. If this option is disabled, each user can access all databases and perform any action.

After making changes you need to restart the mongod service for changes to take effect:

sudo systemctl restart mongod

You can get more information about the configuration options, visit the Configuration File Options documentation page.

Step – 3 Creating Administrative MongoDB User#

You will need create an administrative user account to access and manage the MongoDB instance if you enabled the MongoDB authentication. You can access just typing:

mongo

From inside the MongoDB shell, type the following command to connect to the admin database:

use admin
switched to db admin

Issue the following command to create a new user named admin_user with the userAdminAnyDatabase role:

db.createUser(
   {
     user: "admin_user", 
     pwd: "your_password", 
     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
   }
 )
 Successfully added user: {
     "user" : "admin_user",
     "roles" : [
         {
             "role" : "userAdminAnyDatabase",
             "db" : "admin"
         }
     ]
 }

You can exit from mongo shell by typing:

quit()

Now, access the mongo shell using the administrative user which you have created previously and check the changes:

mongo -u admin_user -p --authenticationDatabase admin

It will prompt to enter password. On success connection select the admin database:

use admin
switched to db admin

You can print list of users by typing:

show users
{
     "_id" : "admin.admin_user",
     "userId" : UUID("dfd92e5s-ds69-3er4-a5c6-654sd0c32e8c"),
     "user" : "admin_user",
     "db" : "admin",
     "roles" : [
         {
             "role" : "userAdminAnyDatabase",
             "db" : "admin"
         }
     ],
     "mechanisms" : [
         "SCRAM-SHA-1",
         "SCRAM-SHA-256"
     ]
 }

Conclusion#

In this guide, you learned how to install MongoDB 6.0 on Debian 11 Bullseye. You can get more details about by visit MongoDB Manual.

Feel free to leave comment, if you have any question or suggestion.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Set up SSH Keys on Ubuntu 22.04
Next Article   How to Change Hostname on Ubuntu 22.04

Related Posts

  • How to Change Hostname Debian 11

    How to Change Hostname on Debian 11

    February 3, 2023
  • How to Install Python 3.11 on Debian 11

    How to Install Python on Debian 11

    January 25, 2023
  • How to Install Jenkins on Debian 11

    How to Install Jenkins on Debian 11

    January 5, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook