Install MongoDB on Debian 10

0
561
Install MongoDB on Debian 10

Follow through this tutorial to learn how to install MongoDB on Debian 10. According to mongodb.com, “MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era...It is a scalable, flexible NoSQL document database platform designed to overcome the relational databases approach and the limitations of other NoSQL solutions.

Read about top 5 features of MongoDB.

Install MongoDB on Debian 10

MongoDB is available in both a community and an enterprise version;

  • MongoDB Community is the source available and free to use edition of MongoDB.
  • MongoDB Enterprise is available as part of the MongoDB Enterprise Advanced subscription and includes comprehensive support for your MongoDB deployment. MongoDB Enterprise also adds enterprise-focused features such as LDAP and Kerberos support, on-disk encryption, and auditing.

In this tutorial, we will learn how to install MongoDB community edition on Debian 10.

Install MongoDB Community Edition on Debian 10

Install MongoDB APT Repo on Debian 10

To be able to install the latest stable versions of MongoDB on Debian 10, you need to install MongoDB APT repository list.

As of this writing, MongoDB 4.4 is the current stable LTS release version. Be sure to replace the version numbers in the commands below accordingly.

Begin by installing the MongoDB APT repo signing key;

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

Next, install MongoDB APT Repo;

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

Update package cache;

apt update

Install latest version of MongoDB Community Edition on Debian 10

Once the repo list is in place, run the command below to install the latest version of MongoDB on Debian 10.

apt install -y mongodb-org

Running MongoDB on Debian 10

When installed, MongoDB creates a systemd unit file called, mongod.service, under /lib/systemd/system/.

This service unit file can be used to manage MongoDB.

To start MongoDB service, execute the command;

systemctl start mongod

To check the status;

systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2021-03-09 14:08:09 EST; 2s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2712 (mongod)
   Memory: 52.5M
   CGroup: /system.slice/mongod.service
           └─2712 /usr/bin/mongod --config /etc/mongod.conf

Mar 09 14:08:09 debian systemd[1]: Started MongoDB Database Server.

To enable it to start on boot;

systemctl enable mongod

You can restart or stop is by executing the commands below respectively;

systemctl restart mongod
systemctl stop mongod

Connecting to MongoDB on Debian

By default, MongoDB listens on TCP port 27017 by default, on a localhost.

apt install net-tools
netstat -altnp | grep :27
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      6618/mongod

In order to connect to it, you need to be logged in to the same host on which MongoDB is running and simply execute the command below;

mongo

Or simply run;

mongo mongodb://localhost:27017

Either of the commands above will launch an interactive MongoDB shell;

MongoDB shell version v4.4.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9d73e6f2-1a6e-4ea7-8887-a71f81dc1cd9") }
MongoDB server version: 4.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
	https://community.mongodb.com
---
...
---
>

To obtain help while logged into the MongoDB interactive shell, run the help command.

help
> help
	db.help()                    help on db methods
	db.mycoll.help()             help on collection methods
	sh.help()                    sharding helpers
	rs.help()                    replica set helpers
	help admin                   administrative help
	help connect                 connecting to a db help
	help keys                    key shortcuts
	help misc                    misc things to know
	help mr                      mapreduce

	show dbs                     show database names
	show collections             show collections in current database
	show users                   show users in current database
	show profile                 show most recent system.profile entries with time >= 1ms
	show logs                    show the accessible logger names
	show log [name]              prints out the last segment of log in memory, 'global' is default
	use <db_name>                set current database
	db.mycoll.find()             list objects in collection mycoll
	db.mycoll.find( { a : 1 } )  list objects in mycoll where a == 1
	it                           result of the last line evaluated; use to further iterate
	DBQuery.shellBatchSize = x   set default number of items to display on shell
	exit                         quit the mongo shell
>

Uninstall MongoDB CE on Debian 10

If for some reasons you want to uninstall MongoDB and remove it completely on Debian 10, you would simply have to stop and purge its by running the commands below;

systemctl stop mongod
apt remove --purge --auto-remove mongodb-org

Remove MongoDB databases;

rm -rf /var/lib/mongodb

And that is how simple it is to install MongoDB on Debian 10.

Want to enable authentication on MongoDB? Follow the link below;

Enable Authentication on MongoDB

Reference

Install MongoDB community Edition on Debian

Further Reading

Getting Started with MongoDB

Other Tutorials

Install LibModsecurity with Apache on Ubuntu 20.04

Update/Change Kibana Visualization Index Pattern

Request control during screen share in Teams on Linux

Install Arkime (Moloch) Full Packet Capture tool on Ubuntu

LEAVE A REPLY

Please enter your comment!
Please enter your name here