Reputation: 153
I have 3 mongo instance runing on AWS, 1 Primary and 2 Secondary. We want all read queries to go to secondary nodes, so we are using these config options when creating the mongoose connection:
options = {
db: {
readPreference: 'secondaryPreferred',
native_parser: true
},
replset: {
strategy: 'ping',
auto_reconnect: false,
}
};
mongoose.connect(databaseUrl, options);
Problem: With these settings, read queries go to both Primary and Secondary nodes, while 2 secondaries nodes are running.
When we use readPreference: 'secondary'
, it's working as we expect: All read queries go only to the secondaries.
Please help me to explain this because with the mongo docs mention:
secondaryPreferred: In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.
Btw, I saw some same issues but all of them still not have a clear solution. :(
We are using:
Upvotes: 0
Views: 10556
Reputation: 153
For people who have same issue, I confirmed that this behaviour originated from the node driver, which the Python driver and the Java driver doesn't seem to exhibit. Mongo developer fixed that bug and waiting to merge to master. You can check in this ticket: https://jira.mongodb.org/browse/NODE-1049
Upvotes: 1