I have a mongodb cluster where shards exist across multi geographically locations and each of those locations have replica members for each shard. I have setup our DR datacenter. Which also has a mongos for creating backups. I want to use the mongodump command to dump the database onto the file system of the mongos instance before sending it off to long term archive. The issue is that mongodump command on sharded clusters sets read pref to secondary so it may dump data from an active production secondary and not the one I have setup for this processes.

When running mongodump against a mongos instance where the sharded cluster consists of replica sets, the read preference of the operation will prefer reads from secondary members of the set. http://docs.mongodb.org/manual/reference/program/mongodump/

I am looking for a way to change the readpref to nearest when running the mongodump command. Or if there is another command that will allow for the same sort of backup as mongodb. (http://docs.mongodb.org/manual/core/read-preference/)

1 Answer 1


The usual reason for sharding is that your workload has exceeded the resources of a single server, so the expectation is that you would not be running mongodump via mongos for a full sharded cluster backup. Backups are instead done by stopping the balancer and then backing up a config server as well as a mongod from each shard.

As at MongoDB 3.0, mongodump does not provide an option to specify read preferences or tags. If you have specific secondaries in your DR data centre for backup purposes, you can use these mongod nodes in your backup procedure.

Recommended backup strategies are included in the MongoDB manual:

Backups with filesystem snapshots are faster to complete (and to restore) because they include all data and indexes. Backups using mongodump export the data and index definitions, but indexes will have to be rebuilt as part of the mongorestore procedure.

FYI, there is an open feature request you can watch/upvote in the MongoDB issue tracker: TOOLS-630: Allow specifying readPreference (including tags).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.