1

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.

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

docker exec -i, not -it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.