Setting readPreference at schema level no longer works in 3.8.4
See original GitHub issueWe’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.
Issue Analytics
- State:
- Created 10 years ago
- Comments:20
Top Results From Across the Web
Read Preference — MongoDB Manual
Configure Read Preference For an example, see connection string. For a given read preference, the MongoDB drivers use the same member selection...
Read more >mongoose/History.md - UNPKG
101, * fix(query): allow setting `writeConcern` schema option to work around MongoDB driver's `writeConcern` deprecation warning #10083 #10009 ...
Read more >History.md - andrew.cmu.ed
addListener #2867 * fixed; call non-hook functions in schema queue #2856 * fixed; ... option #1809 [owenallenaz](https://github.com/owenallenaz) 3.8.4 ...
Read more >api/node_modules/mongoose/History.md - GitLab
4.9.6 / 2017-04-23. fix: update parentArray references when directly assigning document arrays #5192 jhob; docs: improve schematype validator ...
Read more >Mongoose: Read on ReplicaSet - node.js - Stack Overflow
If you want to read from a secondary, you should set your read preference to either of: secondaryPreferred - In most situations, operations...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With
aggregate
queries theread
parameter is not honored. Any way to apply it on aggregation queries as well?@dmitriy-dokshin Please refer to https://github.com/Automattic/mongoose/issues/5522 for the issue.