By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
Cloudbooklet Logo
  • Artificial Intelligence
  • Applications
  • Linux
Notification

Free AI Image Generator

Submit Tool
AI Tools
Cloudbooklet AICloudbooklet AI
Search
AI Tools
Submit Tool
  • Artificial Intelligence
  • Applications
  • Google Cloud
  • Compute Engine
  • Linux

Top Articles

Explore the latest updated articles about AI and technology!
Ai Christmas Songs

How to Create AI Christmas Songs Free – 2023

2
Instagram Profile Views

Instagram Profile Views -What to Expect in 2024

Bing Gpt-4 Deep Search

Bing GPT-4 Deep Search: A New Era of AI-Powered Queries

Follow US
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.

Home » Linux » How to Install MongoDB on Debian 11

Linux

How to Install MongoDB on Debian 11

Last updated: 2023/05/23 at 10:09 AM
By Cloudbooklet
How To Install Mongodb On Debian 11
SHARE
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

How to install MongoDB on Debian 11. MongoDb or Mongo is a most popular open source NoSQL database. It does not rely upon a traditional table based relational database structure. It uses JSON based dynamic schemas which are editable anytime.

In this guide you are going to learn how to install and setup MongoDB on your Debian 11 server. You will also learn to configure remote connection to your Mongo database.

Table of Contents
PrerequisitesInitial Server SetupInstall MongoDBConfigure MongoDBConclusion

This setup is tested on Google Cloud, so it should work fine on other VPS, cloud servers running Debian 11.

Prerequisites

  • A Debian 11 server with sudo access.

Initial Server Setup

Start by updating the server packages to the latest available.

sudo apt update
sudo apt dist-upgrade -y

Now you can proceed to install MongoDB.

Install MongoDB

Here we will install MongoDB Community Edition with LTS using the apt package managed. The current latest version of MongoDB at the time of this article is 5.0.5.

You may need to install gnupg for importing the key.

 sudo apt install gnupg

Import the public key using the following command.

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

Add the MongoDB repository to the sources list. We will use the buster’s repo because by the time of writing this article, the MongoDB Community Edition does not have a separate repository for Debian Bullseye.

The Buster repository is in active development and compatible with Bullseye.

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Update the packages and install MongoDB.

sudo apt update
sudo apt install -y mongodb-org

Once the installation is completed enable MongoDB to start at system startup.

sudo systemctl enable mongod

Start MongoDB server.

sudo service mongod start

You can view the status using the following command.

sudo service mongod status

Output
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-02-18 09:11:56 UTC; 3m ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 1942 (mongod)
     Memory: 164.5M
     CGroup: /system.slice/mongod.service
             └─1942 /usr/bin/mongod --config /etc/mongod.conf

Feb 18 09:11:56 staging systemd[1]: Started MongoDB Database Server.

Configure MongoDB

Now we can secure MongoDB, configure MongoDB to accept remote connections and also create a new database.

Secure MongoDB

Edit MongoDB config file.

sudo nano /etc/mongod.conf

Scroll down to the security section #security and uncomment it and enable authorization. The final edit should look as below.

security:
  authorization: enabled

Enable Remote Connections

To enable remote connections you need to edit the same file and add your internal or private IP to the network interfaces. Your configuration should look like the one below.

net:
  port: 27017
  bindIp: 127.0.0.1,10.128.10.1

Replace 10.128.10.1 with your IP address.

Open firewall if any for the port 27017.

Restart MongoDB.

sudo systemctl restart mongod

Confirm if MongoDB is allowing remote connections using the following command.

sudo lsof -i | grep mongo

You should receive an output similar to the one below.

mongod 1942 mongodb 11u IPv4 31550 0t0 TCP instance_name.c.project_id.internal:27017 (LISTEN)
mongod 1942 mongodb 12u IPv4 31551 0t0 TCP localhost:27017 (LISTEN)

Create MongoDB Admin User

Connect to MongoDB shell using mongosh command.

mongosh

Change to admin database.

use admin

Create admin user with all privileges and setup password.

db.createUser({user: "admin" , pwd: passwordPrompt() , roles: [{ role: "userAdminAnyDatabase" , db: "admin"}]})

Enter password when prompted.

Enter exit to exit the shell.

Now you can use the following connection string to connect to MongoDB.

mongodb://admin:password@External-IP:27017/database

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Conclusion

Now you have learned how to install and setup MongoDB on Debian 11 and also configure remote connections.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

TAGGED: Debian, MongoDB
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Reddit Telegram Copy Link Print
Share
1 Review 1 Review
  • Avatar Of RicardoRicardo says:

    Thanks for posting this article. When I am following your steps I got this error: E: Unable to locate package mongodb-org. It shows after the command: sudo apt install -y mongodb-org

    Reply

Leave a review Cancel reply

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

Please select a rating!

Popular

Ai Quiz Generators
10 Best AI Quiz Generators to Enhance Your Knowledge and Skills
Artificial Intelligence
Ai Podcast Generators
10 Best AI Podcast Generators Tools in 2023
Artificial Intelligence
Chatgpt Voice Chat
How to Use ChatGPT Voice Chat Feature: Tips and Tricks
Artificial Intelligence
Chingu Ai
Chingu AI: A Game-Changer for Workflow Efficiency and Excellence
Artificial Intelligence
- Advertisement -

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Related Stories

Uncover the stories that related to the post!
Ubuntu 23.10
Linux

What’s New and Exciting in Ubuntu 23.10 Mantic Minotaur? A Comprehensive Guide

Symbolic Links In Linux
Linux

Symbolic Links in Linux: What They Are and How to Use Them

Ubuntu Password
Linux

Reset your Forgotten Ubuntu Password in 2 Minutes

&Quot; Systemd Service On Linux
Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

Cloudbooklet Logo
  • Categories:
  • Artificial Intelligence
  • Applications
  • Google Cloud

Quick Links

  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.
Welcome Back!

Sign in to your account

Lost your password?