Thursday, 15 January 2015

node.js - PrimaryPreferred preference for replica set not working -



node.js - PrimaryPreferred preference for replica set not working -

assume got 2 servers same mongodb replica set - 1 mongodb primary , other secondary , arbiter. im using node.js access db (https://github.com/mongodb/node-mongodb-native). after manually disconnect connection between servers, primary becomes secondary , secondary primary because of arbiter. now, want allowed read secondary. code looks like:

var mongoclient = require('mongodb').mongoclient , format = require('util').format; var url = format("mongodb://%s,%s,%s/%s?replicaset=%s&readpreference=%s" , "localhost:27017", , "localhost:27018" , "localhost:27019" , "exampledb" , "foo" , "primarypreferred"); mongoclient.connect(url, function(err db) { if(!err) { console.log("we connected"); var collection = db.collection('somecollection'); collection.find({}).toarray(function(err, items) { // done reading secondary if available }) } });

but says no replica set fellow member available query readpreference undefined , tags undefined. should ?

i think need set slaveok: "true". enable queries on secondary , able query.

regards, sheraz javed

node.js mongodb

No comments:

Post a Comment