I would like to insert data into my mongodb from the command line. The mongodb is running in a docker container.
I want to do the following steps:
- Enter docker container
- Insert data into mongodb
- Exit container
The command that I am using is the following:
docker exec -i <id-of-mongo-container> sh -c "mongo --eval 'db.rules.insert({ description: "test123"})'"
But this throws the following exception:
[js] uncaught exception: ReferenceError: test123 is not defined
I think it is an issue with the quote mark mix, but I am not able to figure out how to get it right. Does someone have an idea on how to fix this?
Research
Something I found from research is that if you swap the string "test123" with a number e.g. 2. Than the command does work.
Therefore, the following command does work.
docker exec -i <id-of-mongo-container> sh -c 'mongo admin --eval "db.rules.insert({ description: 2})"'
It also seems to related to this issue, but it is different because there is an extra set of qoutes from the docker exec.
Cheers!