-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0.37
-
Component/s: None
-
Empty show more show less
Hi
I have a replica set and I am trying to set the read preference to secondaryPreffered with tags.
This is how I am connecting:
var mongo = require('mongodb').MongoClient; var connectionParams = [ 'replicaSet=rs0', 'readPreference=secondaryPreferred', 'readPreferenceTags=dc:c' ]; var options = {}; var connectionString = 'mongodb://localhost:27018,localhost:27019,localhost:27020,localhost:27021/test?' + connectionParams.join('&'); mongo.connect(connectionString, options, function (err, db) { ... });
In mongodb-core/lib/topologies/replset.js:783, filterByTags, it does not seem to compare the tags correctly.
// tags is an array like [{ dc: 'c' }] // so name is the index i.e 0 // serverTag is an object like { dc: 'c' } // So the comparison is always undefined != { dc: 'c' } so it never matches for(var name in tags) { if(serverTag[name] != tags[name]) found = false; }
I have done the same thing with the ruby driver and that seems to work correctly.
require 'mongo' db = Mongo::Client.new( 'localhost:27018', 'localhost:27019', 'localhost:27020', 'localhost:27021'], :database => 'test', :read => { mode: :secondary_preferred, tag_sets: [{ 'dc' => 'c' }] } )
Also, is it possible to configure readPreference in the connect options hash? I have tried but it never seems to work.
Thanks