0 votes
1 view
in SQL by (47.7k points)

I want to execute mongo commands in the 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?

1 Answer

0 votes
by (107k points)

To execute mongo commands through shell scripts you can also evaluate a command using the --eval flag if it is just a single command.

mongo --eval "printjson(db.serverStatus())"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...