I am trying to do in one command, do a bash from docker container, open mongo and make a request with something like
'db.test.find({});'
I am reading from others similar post without success.
This is the command that I am executing.
docker exec -it mongoDB bash -c 'mongo ; use test; db.test.find({})'
And that command give me that
bash: -c: line 0: syntax error near unexpected token {}'
bash: -c: line 0:mongo ; use test; db.test.find({})'
It is that possible?
I hope that you can help me.
Regards,
Roth.
This is actually possibla using a file to execute multiple commands. Put your mongo script into a file.
Example:
myFile.js
File content:
use myDB
show collections
Then you can execute this file with
mongo < myFile.js
In your situation:
docker exec -it mongoDB bash -c 'mongo < myFile.js'
Don't forget to copy this file into your docker container.
You can read more here
You don't really need to copy the script into the container.
You can simply run :
docker exec -it mongoDB bash -c 'mongo' < myFile.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.