mongoose: Setting readPreference at schema level no longer works in 3.8.4
We’ve been using mongoose 3.6.x for many months, and we’ve got one model that we set a secondaryPreferred
read preference on. We run a 3-member replica set, and it makes sense to offload queries for this one particular collection to our secondaries, to lessen the load on the primary.
We set it like this, basically speaking:
var TheSchema = new mongoose.Schema({
someProp: String,
otherProp: Number
}, {readPreference: 'secondaryPreferred'});
This has been running fine for over three months - queries were being properly routed to the secondaries, and everything was great.
After upgrading to mongoose 3.8.4, however, none of these queries work, and all of them return with this:
MongoError: not master and slaveOk=false
at Object.toError (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:110:11)
at /Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:685:54
at Cursor.close (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:959:5)
at commandHandler (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:685:21)
at /Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1806:9
at Server.Base._callHandler (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
at /Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
at MongoReply.parseBody (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/Users/avianflu/dev/blend-clean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:443:20)
at EventEmitter.emit (events.js:95:17)
Any thoughts? I’ve isolated this to the mongoose version upgrade. Server configuration is not relevant.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20
Commits related to this issue
- Use fixed mongodb version, fixes learnboost/mongoose#1895 — committed to AvianFlu/mquery by AvianFlu 10 years ago
- Merge pull request #29 from AvianFlu/master Use fixed mongodb version, fixes learnboost/mongoose#1895 — committed to mongoosejs/mquery by aheckmann 10 years ago
With
aggregate
queries theread
parameter is not honored. Any way to apply it on aggregation queries as well?