listCollections ignores read preference

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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
              Reporter:
              Andreas Kohn
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: