Can I just kill mongod to stop mongo?
It finally succeeded (Ubuntu 15.04) with
//1.find process by name:
$ pgrep mongo
1350
//2.kill mongod-process
$ kill 1350
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.4connecting to: admin2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failedserver 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).
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`'