How to execute mongo commands through shell script

2019-01-03 11:19发布

I want to execute mongo commands in shell script.

I tried following way test.sh

#!/bin/sh

mongo myDbName

db.mycollection.findOne()

show collections

When I execute above script ./test.sh

Then mongo connection established but next commands not executed

How to execute other commands through sh script [test.sh] ?

Please help me

标签: shell sh mongodb
19条回答
Emotional °昔
2楼-- · 2019-01-03 12:23

In my setup I have to use:

mongo --host="the.server.ip:port" databaseName theScript.js 
查看更多
登录 后发表回答