I am very new at Mongo. I am running mongod
as described here in Mac OS X
. I am running two mongod
processes from the command line. If I need to stop the mongod
processes I just execute kill <pid of mongod>
. Is it the recommended way to stop mongod
?

- 41,026
- 70
- 193
- 341
11 Answers
It finally succeeded (Ubuntu 15.04) with
//1.find process by name:
$ pgrep mongo
1350
//2.kill mongod-process
$ kill 1350

- 1,709
- 15
- 10
-
I had to prefix the kill statement with `sudo`. I'm on macOS Catalina – mike Mar 12 '20 at 10:16
-
`killall mongod` will also works (only if you don't want to kill a specific instance) – yves amsellem Mar 28 '23 at 10:33
This is quite late, but I had same problem now, and I found one easy way :
Esan-iMac:~$mongo admin --eval "db.shutdownServer()"
MongoDB shell version: 2.6.4
connecting to: admin
2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failed
server should be down...
It's giving some odd messages, but it works.
And I made alias-command for running it easy.
alias stop-mongo='/opt/mongo/release/bin/mongo admin --eval "db.shutdownServer()"'
This works at least if you start your mongo manually (e.g. with --fork option).

- 716
- 1
- 8
- 9
The accepted answer by Esa is correct. Also, regarding whether using kill is recommended - yes, but with flag -2
or no flag, never use -9
. As mentioned in docs.
kill -2 `pgrep mongo`
Alias
alias stopmongo='kill -2 `pgrep mongo`'

- 3,967
- 2
- 31
- 50
-
-
3@SujayUN - Please check the link to official docs of mongo in the answer. This is recommended by mongo developers. The reason I mentioned not to use -9, was AFAIK(not perfect) it's a kill signal and kills the application instantaneously. -2 in layman terms is a Soft Interrupt, which tells mongo to finish its critical task, don't accept any future data R/W requests and exit. This prevents data corruption. For further reading on Signals, see http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_01.html – saurabheights Sep 11 '17 at 17:28
-
Something you have to use -9 when -2 won't work, in a worst case scenario – Anthony May 29 '21 at 21:02
Windows
use admin
db.shutdownServer()
For systems with auth enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
Linux
mongod --shutdown
you can also use
kill <mongod process ID>
see http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

- 3,513
- 1
- 26
- 26
-
3Thanks. Added that I am running `Mongo` in Mac. It is interesting `mongod` does not have `shutdown` option in Mac :(( – Michael Jan 29 '14 at 12:59
-
see http://stackoverflow.com/questions/8495293/whats-a-clean-way-to-stop-mongod-on-mac-os-x – Juan Rada Jan 29 '14 at 13:04
For year of 2020:
Mongo should be installed through Brew, rather than the old school style on linux: i.e. tar.gz package download/uncompress/configure/run.
In the brew way, if Mongo is installed by brew tap mongodb/brew
and brew install mongodb-community
, you could do as follows to stop (and disable) it alike Systemd on Linux.
~ brew services list
Name Status User Plist
mongodb-community started zhengxin /Users/zhengxin/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
~ brew services stop mongodb-community
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)

- 700
- 1
- 8
- 22
-
-
(Edit: I know the answer refers to the Mac install, but just adding about the official way of installing it on Linux:) today MongoDB Community Edition is available from its own dedicated repositories in many distros, that's the "official" way of installing it on Linux [according to the documentation](https://docs.mongodb.com/manual/administration/install-on-linux/). – TheMechanic Sep 16 '21 at 21:49
Just encountered an issue with "just killing the mongod" in mac...
The mongod is kept running as a service by "launchctl" in mac systems. "just killing" it will kill that service.
Now to use mongo shell we do mongod again, however for other development purpose like connecting from node we need to make sure to run mongod time and again.
Other alternative is shut down the system and start again.
Better Way :
Start using launchctl to manage such services. Here is an example for that :
What is the correct way to start a mongod service on linux / OS X?
The easiest way is Ctrl + C
, which worked for me on a blocking bash shell under El Capitan.

- 947
- 2
- 11
- 20
-
1the thing is that it's running in the background, and the terminal is not availble – Soldeplata Saketos Oct 03 '18 at 09:17
If you have configured autostart, killing the process won't help, new one will start immediately. In order to disable autostart, you have to locate the autostart file first. You can try to find the file using e.g.
find / -name "mongodb.plist"
or locate "mongodb.plist"
After the file is found, remove the autostart config using (you can try without sudo
first, it's not needed if you have done the installation using Homebrew):
sudo launchctl unload -w <file>
If you want to kill the process anyway and it's not using autostart, remember not to use kill -9 <PID>
, it can damage the db. kill -1 <PID>
or kill -15 <PID>
should be safe options.

- 1,046
- 2
- 16
- 29
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/
official guide
remember not to use kill -9
otherwise maybe you need to remove lock file in dbpath

- 9
-
It is very helpful to link to the docu. In addition I would also add a short direct answer to the question, like "Yes: kill
is one of the recommended ways to stop the process". – Falk Tandetzky Sep 02 '20 at 08:39 -
This answer is fine, but almost identical to the answer from saurabheights. In the future please check existing answers first to avoid duplication. – Falk Tandetzky Sep 02 '20 at 08:43