I am using mongoose to connect mongo(v3.04) replica set, and I want to spread all my requests to all nodes in set. However, after doing like the following, my secondary never got hit, my connection string and options like the following:
let connectionString = 'mongodb://ip1:27017/db, ip2:27017/db';
mongoose.connect(connectionString, {
server: {
socketOptions: {keepAlive: 1},
readPreference: "nearest",
strategy: "ping"
},
replset: {
rs_name: 'ReplicaSet',
socketOptions: {keepAlive: 1},
strategy: 'ping',
readPreference: 'nearest',
poolSize: 10
}
});
It looks like the mongoose totally ignore the readPreference settings I passed. I already tried many ways mentioned here, but so far no luck. Anyone could give me a hint?