mongodump ignore some specified collections

sashimi picture sashimi · Apr 12, 2013 · Viewed 31.7k times · Source

I was trying to backup my mongo database on the product sever.and then restore then back to the staging server. and here comes some problem, there are a lot of collections in db, I want to igonre some collections that I don't want to restore on staging server.

I can approach this by dumpping the staging db, dumpping the producting db, and then restore the prodct to staging useing --drop option. and restore the specified collections in staging db. uh..it's really bad.

1. dump producting db

mongodump --host product-server-host --username abcd --password bcda -d db -o pruduct-dump-dir

2. dump staging db

mongodump --host staging-server-host --username abcd --password bcda -d db -o staging -dump-dir

3. restore all collection, then restore the collection back restore pruduct-dump-dir to staging server

mongorestore --host staging-server-host --username abcd --password bcda --drop pruduct-dump-dir

mongorestore --host staging-server-host --username abcd --password bcda --drop --collection coll pruducting-dump-dir

Is there any option like ignore-collection when I'm dumpping? any suggestion will be appreciated :3

Answer

Daniel Pérez Rada picture Daniel Pérez Rada · Mar 11, 2015

Now available from version 3.0.0

--excludeCollection <collection_name>
--excludeCollectionsWithPrefix <collection_prefix>

Repeat to exclude more than 1

Checkout the documentation