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

listCollections ignores read preference

      Assume this code:

      var MongoClient = require('mongodb').MongoClient;
      MongoClient.connect('mongodb://SERVER:27017/test?readPreference=secondaryPreferred', function(err, db) {
      	db.listCollections().toArray().then(collections => console.log(collections)).then(() => db.close());
      });
      

      This should list all collections in the 'test' db, regardless of whether 'SERVER' is currently a primary or not.

      This does not work: if SERVER is a secondary, then this will log something like:

      (node:16946) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: not master and slaveOk=false
      

      I think the problem can be fixed with the attached patch.

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            ankon Andreas Kohn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: