-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.1.1
-
Component/s: Native
-
Environment:Node v8.9.4
Replica set: Primary, Secondary, Arbiter
The following code will execute against the primary instead of the secondary:
const url = 'mongodb://user:password@localhost:27018,localhost:27017/test?replicaSet=replset'; MongoClient.connect(url, (err, client) => { const cursor = db.collection('test').find({}); cursor.count(true, { readPreference: ReadPreference.SECONDARY } ).then(console.log); );
It appears that the count function does not respect the read preference.
Documentation: http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#count
I have not tried to give the options to the find function, but setReadPreference works.