We have a mongo db replica set configuration with 1 primary and 2 secondaries. We have set the read preference to primary because one of our secondary is in a remote region and do not want read operations to go on that node.
If I run the collection.find() method (which is using MongoCursor and iterates through the response), one by one in debug mode, I see all the calls going to primary.
The above can be verified with 2 ways:
- mongo driver log on the client shows the command is sent to the primary mongo server
- the mongodb.log on the server prints the find operation (enabling
slowmsoption)
However, if I run the same without debug mode (higher speed + load), the mongodb.log for both servers start showing the find operation. This is unexpected as we want the calls to only go to primary and not to the remote secondary. Also, the mongo driver log on the client shows command is send only to the primary mongo server.
Also, the difference in the primary and secondary mongodb.log is that the readPreference is shown "secondaryPreferred" in the secondary mongodb.log (and we do not set this preference anywhere in the code).
What could be the reason for seeing the logs in the secondary mongodb.log ?
Is it just log printing and the calls are really going to primary ? Or the primary server is really forwarding the calls to secondary with secondaryPreferred read preference ?