Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-599

Mongo DB Core - Replica Set readPreference not matching tags correctly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.0
    • Affects Version/s: 2.0.37
    • Component/s: None

      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

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            delwyn Delwyn de Villiers
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: