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

Can't connect when using readPreference secondary

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.5
    • Component/s: Lambda
    • Environment:
      NodeJS 4.9.1, 8.10.0.
      MongoDB 3.4.14
      Mongo Atlas (AWS us-east-1)

      When making a mongodb connection with readPreference=secondary, the connection hangs and never succeeds. It also doesn't return an error.

      Here's some code to reproduce it:

      // setup
      const MongoClient = require('mongodb').MongoClient;
      
      // sample connection string
      const MONGO_URL = 'mongodb://dev-api:PASSWORD@testing-dev-shard-00-00-rbwsc.mongodb.net:27017,testing-dev-shard-00-01-rbwsc.mongodb.net:27017,testing-dev-shard-00-02-rbwsc.mongodb.net:27017/testingdb?ssl=true&replicaSet=testing-dev-shard-0&authSource=admin'
      

      Working example:

      // Default read preference
      MongoClient.connect(MONGO_URL).then(function(client) {
          console.log(client);
          process.exit();
      }).catch(function(err) {
          console.log(err);
          process.exit();
      });
      

      Not working example:

      // Secondary read preference
      MongoClient.connect(MONGO_URL, {
          readPreference: 'secondary'
      }).then(function(client) {
          console.log(client); // never reaches here
          process.exit();
      }).catch(function(err) {
          console.log(err); // never reaches here
          process.exit();
      });
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            joe@dashride.com Joseph Thibeault
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: