DEV Community

Surya
Surya

Posted on

MongoDB tutorial

@santhoshnc

For Linux users:

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

The above command will download the gpg key from mongodb official site.

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

This line adds MongoDB’s official repository to Debian and ties it to the trusted GPG key.
Without it → APT won’t know where to fetch MongoDB packages.

  1. sudo apt install mongodb-org
    APT downloads MongoDB packages from their servers.
    The GPG key ensures that the package is officially from mongodb server.

  2. sudo start systemctl mongod
    sudo enable systemctl mongod
    So after doing both, MongoDB is running now and will always run on boot.

  3. mongod --version
    shows version of mongodb which helps us to ensure the installation of mongodb

  4. mongosh
    this command helps you to launch CLI of mongodb

  5. now go to mongodb atlas and create an account for that.

  6. select free plan and create an cluster

it will load sample dataset, next click the connect button

choose shell here

  1. choose "I have the mongodb shell installed", next copy the command to establish connection and paste the command in the linux shell

  2. click the browse collections and click create database

  3. Inside your database, click "insert document" and insert the data in form of key value pair

Top comments (0)