Lesson 1: Managing MongoDB Servers / Learn

Code Summary: Managing MongoDB Servers

Review the following code, which demonstrates how to install, start, and stop mongod.

Install MongoDB Community Edition

Follow these steps to install MongoDB 6.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux, using the apt package manager.

  1. In the terminal, use the following command to import the public key that’s used by the package management system:
  2. wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

  3. Create a list file for MongoDB:
  4. echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
    
    

  5. Reload the local package database:
  6. sudo apt-get update

  7. Install the latest stable version of MongoDB Community Edition:
  8. sudo apt-get install -y mongodb-org
    

Start, Stop, and Check the Status of mongod

To start the mongod service, use the following command:

sudo systemctl start mongod

To check the status of a mongod service, use the following command:

sudo systemctl status mongod

To stop a mongod service from running, use the following command:

sudo systemctl stop mongod