How to Operate MongoDB through shell Scripts

  mongodb, question

Automate MongoDB with shell Scripts

Run the written. /show.sh script
It was found that the mongo link could be established, but the second link could not be started.

The script reads as follows

#!/bin/sh
mongo WordPress
show collections
db.posts.find().limit(10)

I don’t know why.

The mongo shell statement starts from the second one, and of course it cannot be run.

This should be the case:

#!/bin/sh
mongo WordPress --eval "show collections;db.posts.find().limit(10);"