-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0.53, 2.1.2
-
Component/s: None
-
Labels:
-
Environment:Ubuntu 14.04, Mongo 2.4.10, Node 0.10.24
-
Empty show more show less
The latest versions of the node driver don't seem to respect the 'primaryPreferred' read preference and treat it as 'primary': notably, when the primary node in a replica set goes down, read commands fail. This seems to be the case regardless of whether the read preference is passed via the connection url or as an option to a find() command.
This issue is not present in 1.4.39.
Some sample code:
var mongodb = require('mongodb'), connUrl = 'mongodb://fakeUser:fakePassword@33.33.33.100:27017,127.0.0.1:27017/testDb?replicaSet=devReplSet&readPreference=primaryPreferred', opts = { server: { autoReconnect: true }, db: { native_parser: true, bufferMaxEntries: 0 } }; mongodb.MongoClient.connect(connUrl, opts, function(err, db) { if (err) throw err; db.collection('foo').find().limit(1).next(console.log); // succeeds, prints item // restart primary or issue rs.stepDown() command on primary db.collection('foo').find().limit(1).next(console.log); // fails with error 'no connection available for operation and number of stored operation > 0' });