I have a two-machine MongoDB replica set. The primary is private (used internally) and it is critical that it stays running smoothly. The secondary is our public copy of the primary which is non-voting. It does not matter much if the secondary crashes (e.g. if there is too much read load on the machine).
I want the secondary to take all the read load that comes from the public internet. I have enabled reads from the secondary with rs.slaveOk()
. However, someone can still set the read preference to primary
to read from the primary.
How can I prevent the secondary from forwarding reads to the primary, thereby risking to overload the primary?