DEV Community

Cover image for Restart MongoDB Commands
Kevinleary.net
Kevinleary.net

Posted on Originally published at kevinleary.net

Restart MongoDB Commands

MongoDB Logo It’s not entirely clear how to quickly start, stop and restart MongoDB with a command line, so I’ve documented it here based on the need for a simple, straightforward approach.

MongoDB Commands

Use the following commands to start, stop or restart MongoDB.

Mac OS

On Mac OS the installation process for MongoDB’s Community Edition uses the Homebrew brew package manager with the help of the official MongoDB tap. Starting, stopping and restarting MongoDB on a Mac involves using brew services.

Start

brew services start mongodb-community@6.0
Enter fullscreen mode Exit fullscreen mode

Stop

brew services stop mongodb-community@6.0
Enter fullscreen mode Exit fullscreen mode

Restart

brew services restart mongodb-community@6.0
Enter fullscreen mode Exit fullscreen mode

Ubuntu/Debian

MongoDB can be managed on linux machines in two ways:

  1. service command
  2. systemctl command

service is used for running init scripts from the terminal. systemctl is a newer initialization system that aims to replace SysVInit. Most Linux distributions such as Debian and Red Hat are already using SystemD as their init system out of the box, so I’m including both here for reference.

Start

For systemd:

sudo systemctl start mongod
Enter fullscreen mode Exit fullscreen mode

Or for service:

sudo service mongod start
Enter fullscreen mode Exit fullscreen mode

Stop

For systemd:

sudo systemctl stop mongod
Enter fullscreen mode Exit fullscreen mode

Or for service:

sudo service mongod stop
Enter fullscreen mode Exit fullscreen mode

Restart

For systemd:

sudo systemctl restart mongod
Enter fullscreen mode Exit fullscreen mode

Or for service:

sudo service mongod restart
Enter fullscreen mode Exit fullscreen mode

Windows

I’ve never used MongoDB in a Windows IIS environment, but for reference here’s what MongoDB has documented for starting, stopping and restarting the service.

Start

In the Windows Services console right-click on the MongoDB service and click Start.

Stop

In the Windows Services console right-click on the MongoDB service and click Stop.

Restart

In the Windows Services console right-click on the MongoDB service and click Start/Restart.

Top comments (0)