How can I restore a single collection from a MongoDB online Snapshot?
I have tried downloading the snapshot and copying it over the local Docker data folder of MongoDB. It does start but then I am no longer able to login using either the old root user password, or any of the users in the MongoDB Atlas database.
I need to be able to restore just a single collection from one of the backups from a point in time. I know if I make an archive using mongodump, I can restore it locally with mongorestore. However, mongorestore doesn’t let me specify the downloaded gz file. It reports it is in an incorrect format.
I have deleted the contents of a collection by accident, and just need to get that data back either using the online UI or a local docker copy.
Thanks
To restore a single collection from an online MongoDB snapshot, you can use the following steps:
- Download the snapshot that you need to restore.
- Create a new MongoDB instance.
- Restore the snapshot to the new MongoDB instance using the
mongorestore
command and specify the path to the snapshot:
mongorestore --host <hostname> --port <port> --username <username> --password <password> --db <database> --collection <collection> <path-to-snapshot>
- Once the restore is complete, you can copy the single collection to your original MongoDB instance using the
mongoexport
and mongoimport
commands:
mongoexport --host <new-instance-hostname> --port <new-instance-port> --username <new-instance-username> --password <new-instance-password> --db <new-instance-database> --collection <collection> --out <collection>.json
mongoimport --host <original-instance-hostname> --port <original-instance-port> --username <original-instance-username> --password <original-instance-password> --db <original-instance-database> --collection <collection> --drop --file <collection>.json
This way, you can restore a single collection from a MongoDB online snapshot without affecting the rest of the data in your original instance.
1 Like