How to execute mongo commands from bash?

后端 未结 3 978
旧时难觅i
旧时难觅i 2021-02-19 18:00

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:39

    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

提交回复
热议问题