I am trying to run this command from bash script:
mongo 192.168.10.20:27000 --eval "use admin && db.shutdownServer() && quit()"
but i get this error :
[rs.initiate() && use admin && db.shutdownServer() && quit()] doesn't exist
how can i do it without using a js file?
There are differences between interactive & scripted mongo
shell sessions. In particular, commands like use admin
are not valid JavaScript and will only work in an interactive shell session.
The working equivalent of your shutdown command line would be:
mongo 192.168.10.20:27000/admin --eval "db.shutdownServer()"
You can include the database to use in the connection string, and there is no need to quit from a scripted mongo
shell session.
If you do need to change databases from a scripted session, there is a db.getSiblingDB()
JavaScript function. An alternative way to write the shutdown command above would be:
mongo 192.168.10.20:27000 --eval "db=db.getSiblingDB('admin');db.shutdownServer()"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments