Skip to content

Instantly share code, notes, and snippets.

@hesoyamcode
Last active September 18, 2019 07:02
Show Gist options
  • Save hesoyamcode/368517a290934b8196e4f5608cdacb59 to your computer and use it in GitHub Desktop.
Save hesoyamcode/368517a290934b8196e4f5608cdacb59 to your computer and use it in GitHub Desktop.
Mongodb dump, restore, import, export
The counterpart to mongodump is mongorestore (and the counterpart to mongoimport is mongoexport) -- the major difference is in the format of the files created and understood by the tools (dump and restore read and write BSON files; export and import deal with text file formats: JSON, CSV, TSV.
If you've already run mongodump, you should have a directory named dump, with a subdirectory for each database that was dumped, and a file in those directories for each collection. You can then restore this with a command like:
mongorestore -h host.com:port -d dbname_test -u username -p password dump/dbname/
Assuming that you want to put the contents of the database dbname into a new database called dbname_test.
Src: https://stackoverflow.com/questions/8070298/how-to-import-dumped-mongodb
```
mongorestore --username your_username --password your_password --authenticationDatabase admin -d database_name dir/to/bson_json
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment