Reputation: 3267
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.
Upvotes: 1
Views: 3380
Reputation: 47975
In v3.4 you can use the --nsExclude
and/or --nsInclude
options to create a superset of the functionality of the --collection
option
For example:
// only restore documents in the transactions database
// and exclude collections whose name ends with "_dev"
mongorestore --nsInclude 'transactions.*' --nsExclude 'transactions.*_dev' dump/
More details in the docs.
Update in response to this comment:
hmm but the collections names I want to restore have no any similar pattern to use wild cards..
If the collection names you do not want to restore can be isolated using a wildcard pattern then you could just use --nsExclude
. If not, then mongorestore
cannot do what you want in a single call so instead you could invoke mongorestore
in a loop within a batch or shell script, invoking mongorestore
once for each of the collection names you want to restore.
Upvotes: 1