1, mongo shell : 两步命令
a. use admin
b. db.shutdownServer()
2. bash shell :任何一个都可以
echo "db.shutdownServer()"|mongo admin --port 37017
mongo admin --port 37017 --eval "db.shutdownServer()"
mongo --eval "db.getSiblingDB('admin').shutdownServer()"
alias mongostop='mongo admin --eval "db.shutdownServer()"'
3. 帮助信息
2009 $ h mongo
MongoDB shell version: 3.2.14
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
Options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no
'db address' arg expected
--norc will not run the ".mongorc.js" file on
start up
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
4. 可以使用“kill ”的方式关闭,这种方式也是“cleanly”;如果使用“kill -9
”方式就是强制线程退出,可能会导致数据丢失。如果在非fork下运行mongod,直接在shell上使用“CTRL-C”方式也是“cleanly”退出。对于线上环境,最好不要“kill
-9”。