When using mongodump to back up a replica set, you need to use either the --uri or the --host option to specify a list of hosts in the replica set. Using our Docker replica set model as an example, the string would appear as follows:
mongodump --uri="mongodb://member1.biglittle.local:27017,\
member2.biglittle.local:27017,member1.biglittle.local:27017/? \
replicaSet=learn_mongodb"
Here is an alternate syntax that does the same thing:
mongodump --host="learn_mongodb/member1.biglittle.local:27017,\
member2.biglittle.local:27017,member1.biglittle.local:27017"
Data is normally read from the primary. If you wish to allow the backup to be read from a secondary, add the --readPreference option. If all you want to do is to indicate that the backup can occur from a secondary, add the following option to either of the preceding examples:
mongodump <...> --readPreference=secondary
A final consideration...