Mongoose / MongoDB replica set using secondary for reads Mongoose / MongoDB replica set using secondary for reads mongoose mongoose

Mongoose / MongoDB replica set using secondary for reads


As per the project issues on gitHub there was a issue where the Read preference does not seem to be working when upgrading to the newest version (mongoose@3.8.1 & mongodb@1.3.23) as all the reads are being done from the master and not from the secondary servers.

As per the comments this problem doesnot come when you roll back to older version(mongoose@3.6.4 & mongodb@1.2.14), reads will start going to the secondaries(collection level). This issue is meant to be fixed in version 3.8.7.

Please reference the following issues for the same:

https://github.com/Automattic/mongoose/issues/1833https://github.com/Automattic/mongoose/issues/1895


How can I check if the secondary read or nearest is working,

If you have access to your machines, a simple way to check which ones are being queried is with mongostat. Just log into one of your servers and run

mongostat --discover

This will give you basic output on inserts/queries/updates/delete that are being run on each machine in your replica set. If you have a quiet system it will be easy to see where the queries are being redirected to so you can at least know whether your secondaries are being hit.

If they aren't, you will need to investigate your driver settings.


Instead of secondary can you check with nearest option. I guess that should work.Check this link.http://docs.mongodb.org/manual/reference/read-preference/#nearest