Mongodb – How restore a specific database from backup using mongorestore command

mongodb

I created a backup of all my databases using mongodump command. Now I want to restore a specific database using mongorestore command.

How is this possible, I use this command: –db option then mongodb doesn't restore a specific database.

Best Answer

To restore a single database you need to provide the path to the dump directory as part of the mongorestore command line.

For example:

# Backup the training database
mongodump --db training

# Restore the training database to a new database called training2
mongorestore --db training2 dump/training

The --db option for mongodump specifies the source database to dump.

The --db option for mongorestore specifies the target database to restore into.