MongoDB Installation / DONE

This point is required only when installing in Source mode by default we use Docker system in which MongoDB does not need to be installed separately

Note: This manual is for Debian 11 only, if you have a different version of the system, please use the official documentation.

Adding keys:

sudo apt-get install -y gnupg
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
   --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update

Installation:

apt-get install -y mongodb-org

Starting and adding to autorun:

sudo systemctl start mongod
sudo systemctl daemon-reload
sudo systemctl enable mongod

Creating a database and password:

mongosh

continue with the instructions below

Attention! In the code below there are variables you need to make up your own (ADMIN_NAME, ADMIN_PASSWORD, DB_NAME, USER_NAME, YOUR_PASSWORD, DB_NAME) these data should not be disclosed to anyone, they are accesses to your databases, if you disclose them or use the command without changes, you risk being hacked!

use admin;
db.createUser({
  user: "ADMIN_NAME",
  pwd: "ADMIN_PASSWORD",
  roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
});
use DB_NAME;
db.createUser({
  user: "USER_NAME",
  pwd: "YOUR_PASSWORD",
  roles: [ { role: "readWrite", db: "DB_NAME" } ]
});
exit

Activation of authorisation for MongoDB

nano /etc/mongod.conf
/etc/mongod.conf
security:
      authorization: "enabled"   

Last updated