How to dump and restore in MongoDB

1. Dump

Local database

mongodump --db=test-db

Remote database


After dumping you will have a dump directory

➜ ~ tree dump
└── test
    ├── cats.bson
    ├── cats.metadata.json
    ├── device.bson
    ├── device.metadata.json
    ├── event_data.bson
    ├── event_data.metadata.json
    ├── organisation.bson
    ├── organisation.metadata.json
    ├── organization.bson
    └── organization.metadata.json

2. Restore

This will restore everything to your local mongo instance

mongorestore  dump/

If you want to dump a specific collection, you can filter like below while restoring

mongorestore --nsInclude=test.cats dump/