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

ReadPreference primaryPreferred is not respected

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.3, 2.0.54
    • Affects Version/s: 2.0.53, 2.1.2
    • Component/s: None
    • Labels:
    • Environment:
      Ubuntu 14.04, Mongo 2.4.10, Node 0.10.24

      The latest versions of the node driver don't seem to respect the 'primaryPreferred' read preference and treat it as 'primary': notably, when the primary node in a replica set goes down, read commands fail. This seems to be the case regardless of whether the read preference is passed via the connection url or as an option to a find() command.

      This issue is not present in 1.4.39.

      Some sample code:

      var mongodb = require('mongodb'),
          connUrl = 'mongodb://fakeUser:fakePassword@33.33.33.100:27017,127.0.0.1:27017/testDb?replicaSet=devReplSet&readPreference=primaryPreferred',
          opts = { server: { autoReconnect: true }, db: { native_parser: true, bufferMaxEntries: 0 } };
       
      mongodb.MongoClient.connect(connUrl, opts, function(err, db) {
          if (err) throw err;
          
          db.collection('foo').find().limit(1).next(console.log);
          // succeeds, prints item
          
          // restart primary or issue rs.stepDown() command on primary
          
          db.collection('foo').find().limit(1).next(console.log);
          // fails with error 'no connection available for operation and number of stored operation > 0'
      });
      

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            leichter Evan Leichter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: