How to execute mongo commands through shell scripts?
Asked 07 September, 2021
Viewed 334 times
  • 53
Votes

I want to execute mongo commands in shell script, e.g. in a script test.sh:

#!/bin/sh
mongo myDbName
db.mycollection.findOne()
show collections

When I execute this script via ./test.sh, then the connection to MongoDB is established, but the following commands are not executed.

How to execute other commands through shell script test.sh?

21 Answer