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.
Use the following commands to start, stop or restart MongoDB.
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.
brew services start [email protected]
brew services stop [email protected]
brew services restart [email protected]
MongoDB can be managed on linux machines in two ways:
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.
sudo systemctl start mongod
sudo service mongod start
sudo systemctl stop mongod
sudo service mongod stop
sudo systemctl restart mongod
sudo service mongod restart
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.
In the Windows Services console right-click on the MongoDB service and click Start.
In the Windows Services console right-click on the MongoDB service and click Stop.
In the Windows Services console right-click on the MongoDB service and click Start/Restart.