Reputation: 2064
I had a replica set with primary/secondary and read preference as NEAREST. Through MongoStat, I can see that requests are going to the replica set member where the mongod instance and nodejs is running and not to the other member on a different aws instance. Pinging is not enabled between the two. I can also verify that the other instance is accessible by changing the read preference. Working fine with my java client. Should the other instance be ping-able for read sharing? SecondaryAcceptableLatencyMS is set at 500. Here is the sample code snippet I am trying to execute.
var replSet = new ReplSetServers( [
new Server( "localhost", 27017, { auto_reconnect: true, native_parser: true, slaveOk: true } ),
new Server( "<replmem1>", 27017, { auto_reconnect: true, native_parser: true, slaveOk: true } ),
new Server( "<replmem2>", 27018, { auto_reconnect: true, native_parser: true, slaveOk: true } )
],
{read_secondary:true, secondaryAcceptableLatencyMS:500 }
);
var dbCon = new Db("emails_" + postParams["campaign_id"], replSet, {safe: true, readPreference: mongo.ReadPreference.NEAREST});
dbCon.open(function(err, db) {
Upvotes: 0
Views: 1237
Reputation: 10790
Its not documented well yet but a strategy
option must be specified when using NEAREST.
var replSet = new ReplSetServers( [
new Server( "localhost", 27017, { auto_reconnect: true, native_parser: true, slaveOk: true } ),
new Server( "<replmem1>", 27017, { auto_reconnect: true, native_parser: true, slaveOk: true } ),
new Server( "<replmem2>", 27018, { auto_reconnect: true, native_parser: true, slaveOk: true } )
],
{read_secondary:true, secondaryAcceptableLatencyMS:500, stragegy: 'ping' }
);
Upvotes: 2