Doron Go
Doron Go

Reputation: 241

mongodump - query for one collection

I'm trying to write a mongodump / mongorestore script that would copy our data from the production environment to staging once a week. Problem is, I need to filter out one of the collections. I was sure I'd find a way to apply a query only on a specific collection during the mongodump, but it seems like the query statement affects all cloned collections. So currently I'm running one dump-restore for all the other collections, and one for this specific collection with a query on it.

Am I missing something? Is there a better way to achieve this goal? Thanks!

Upvotes: 0

Views: 684

Answers (1)

user12582392
user12582392

Reputation:

It is possible.

--excludeCollection=<string>

Excludes the specified collection from the mongodump output. To exclude multiple collections, specify the --excludeCollection multiple times.

Example

mongodump  --db=test --excludeCollection=users --excludeCollection=salaries

See Details here.


Important mongodump writes to /dump folder. If it's already there, it will overwrite everything.

If you need that data rename the folder or give mongodump an --out directory. Otherwise you don't need to worry.

Upvotes: 0

Related Questions