MongoDB Installation

  1. From the terminal, install gnupg and curl if they are not already available

sudo apt-get install gnupg curl

To import the MongoDB public GPG key, run the following command:

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

  1. Create a /etc/apt/sources.list.d/mongodb-org-7.0.list file for MongoDB

echo "deb[signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

  1. Issue the following command to reload the local package database

sudo apt-get update

  1. Install the MongoDB packages

sudo apt-get install -y mongodb-org

  1. Start the mongod process by issuing the following command

sudo systemctl start mongod

  1. Verify that MongoDB has started successfully

sudo systemctl status mongod

7. Configure MongoDB in /etc/mongod.conf
---
storage:
 dbPath: /var/lib/mongodb

systemLog:
 destination: file
 logAppend: true
 path: /var/log/mongodb/mongod.log

net:
 port: 27017
 bindIp: 127.0.0.1

processManagement:
 timeZoneInfo: /usr/share/zoneinfo

security:
 authorization: enabled
---
Most of the above config is configured by default, you might want to set bindIp and port to the one you want and enable authorization, which is not enabled by default.
You have to create an user account before enabling authorization, or you will not be able to log in to mongodb without any users configured.