mongodbdockermongoexport

Why doesn't mongoexport generate the output file


I have a Mongo database on my server and I can connect to it using docker. I run the following command:

docker exec -it mongodb mongoexport --port 27017 -u "username" -p "password" --authenticationDatabase "admin" -d databaseName -c user --out /var/www/myTest/output.json

It seems that the command works without any problem and I get the message:

connected to: mongodb://localhost:27017/
exported 16 records

However, when I use FileZilla and look at the directory /var/www/myTest, there is no file there. The folder is empty (I had created the folder myself earlier. If I use a new folder name, the folder is also not generated).

What have I done wrong? Is the file somewhere else?

Thanks in advance,


Solution

  • That directory and the file is inside the mongoexport container.

    UPDATE:

    You could also bind mount a directory from your host to the containers:

    docker run --rm -v /var/www/myTestOnHost:/var/www/myTestOnContainer -it mongodb mongoexport --port 27017 -u "username" -p "password" --authenticationDatabase "admin" -d databaseName -c user --out /var/www/myTestOnContainer/output.json

    docs: https://docs.docker.com/storage/bind-mounts/

    --rm flag for docker run will remove the container when it finished running, that is executing the mongoexport --port 27017 -u "username" -p "password" --authenticationDatabase "admin" -d databaseName -c user --out /var/www/myTestOnContainer/output.json command