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 [email protected]
Stop
brew services stop [email protected]
Restart
brew services restart [email protected]
Ubuntu/Debian
MongoDB can be managed on linux machines in two ways:
service
commandsystemctl
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
Or for service
:
sudo service mongod start
Stop
For systemd
:
sudo systemctl stop mongod
Or for service
:
sudo service mongod stop
Restart
For systemd
:
sudo systemctl restart mongod
Or for service
:
sudo service mongod restart
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.