mongodump ignore some specified collections
Solution 1:
Now available from version 3.0.0
--excludeCollection <collection_name>
--excludeCollectionsWithPrefix <collection_prefix>
Repeat to exclude more than 1
Checkout the documentation
Solution 2:
mongodump --db test --excludeCollection=users --excludeCollection=salaries
Solution 3:
You can add --collection COLLECTION_NAME
to dump the collection you need. By default, if you do not specify a collection to dump from a database, MongoDump will dump all collections in that database.
Solution 4:
As of Mongo 3.4, you can now specify an --nsExclude <namespace pattern>
option when restoring from a Mongo database dump, which will exclude the specified namespaces from the restore operation. This is particularly useful when the mongodump
operation has already occurred.
Official documentation here: https://docs.mongodb.com/manual/reference/program/mongorestore/#cmdoption-nsexclude
You can exclude multiple collections with wildcards:
mongorestore --db test --nsExclude 'test.*_tmp'
Or alternatively, specifying multiple --nsExclude
options work as well:
mongorestore --db test --nsExclude 'test.collection1' --nsExclude 'test.collection2'