How to execute mongo commands from bash?

后端 未结 3 1975
时光说笑
时光说笑 2021-02-19 18:04

I am trying to run this command from bash script:

 mongo 192.168.10.20:27000 --eval \"use admin && db.shutdownServer() && quit()\"
3条回答
  •  北海茫月
    2021-02-19 18:41

    From the mongo docs:

    --eval option

    Use the --eval option to mongo to pass the shell a JavaScript fragment, as in the following: mongo test --eval "printjson(db.getCollectionNames())"

    You can also put your JS Fragments into a .js file then do:

    mongo < myScript.js
    

    You may also find more useful stuff in this SO question

提交回复
热议问题