-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.2.31
-
Component/s: MongoDB 3.4
-
Empty show more show less
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.