Skip to content

Instantly share code, notes, and snippets.

@ironbyte
Forked from JaniAnttonen/mongoDump.md
Created April 30, 2019 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironbyte/ab2f7128f89de652d3be2f9d58227fb1 to your computer and use it in GitHub Desktop.
Save ironbyte/ab2f7128f89de652d3be2f9d58227fb1 to your computer and use it in GitHub Desktop.
Export Docker MongoDB collection as a JSON file

First, find the container that runs your MongoDB and ssh into it.

Then, find the collection you want to export:

mongo
show dbs
use <database>
show collections
exit

Then, run mongoexport command in the shell (not in mongo):

mongoexport -d <database-name> -c <collection-name> --out output.json

Then, on your local machine, copy the file from inside the docker container to your current folder:

docker cp <mongodb docker container name>:/output.json .

Don't forget the dot from the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment