Node.js driver 3.6.3 with Replica Set: not master and slaveOk=false

Hello,

I wasn’t sure if this is the correct section to post this in, so apologies if it’s wrong here.
After updating to Node js driver 3.6.3 some errors occur to our logs:

[ERROR] MongoError: not master and slaveOk=false
This error occurs daily in logs.
The configuration for connection is set with: " “readPreference”: “secondaryPreferred”,".
I am not sure if it is due to node.js driver upgrade or we have some other problems. But we inspect mongo logs and it does not have any failover or other similar issues.
Until now, we do not have this kind of logs.

Do you have any suggestions?

Thanks

It looks like you client is connected directly to a secondary. You have to specify the replica set name on the URI so that the client automatically detect and use the primary.

1 Like

Hello, after more investigation it seems that a specific query fails, the one that has “setReadPreference(“primary”)”:

await incidentCollection.find({"_id": customId}, {limit: 1}).setReadPreference(“primary”).next();

Any ideas?

Thanks.

Hello,
The following string is used as connection string:

mongodb://user:pass@name1,name2,name3/admin?replicaSet=events&readPreference=secondaryPreferred&w=majority

Connections options:

{
    “readPreference”: “secondaryPreferred”,
    “poolSize”: 5,
    “connectTimeoutMS”: 0,
    “socketTimeoutMS”: 0,
    “useUnifiedTopology”: true,
    “writeConcern”: {
        “w”: 1
    }
}

Set up the mongo connection code:

let mainDb = await this.MongoClient.connect(serverUri, options);

Thanks,
Iulian