How do I restore multiple collections at once in mongodb.
I have tried
mongorestore -c Role -c UserAccount -c Permission -d movie-app dump/
and I got an error file dump is a directory, not a bson file
I can restore single collection at a time I have to specify the bson file like
mongorestore -c UserAccount -d movie-app dump/movie-app/UserAccount.bson
I need to know how do I restore multiple collection with one command.
Best Answer
Try these parameter to Include or exclude collections
During restoration, you can ignore the unwanted collections.
EG:
Dump all the collections
mongodump --db bhuvi --out /tmp
My dump folder has 3 collections.
Restoring coll2 and coll3 collections
I want to restore coll2 and coll3 in the test db.
mongorestore --db test --nsExclude 'test.*1' /tmp/bhuvi/
Check the collections
For restore collections with similar names
mongorestore --db test --nsInclude 'test.coll*' /tmp/bhuvi/
Restore collections with different pattern
There is no straight forward method for this, but we can create a loop to restore this.
create a file with list of collections that we need to restore
shell script for restore in loop
root@lin_sql1:/home/ubuntu# ./restore
Check the collections