Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange mongodb and mongoose error: not master and slaveOk=false error

I'm getting a strange error in my node.js app

not master and slaveOk=false code 13435

I'm doing a findOne query using mongoose 4.0.2 hitting a mongodb 3.0.1. The query was working earlier today.

What is this error? I'm running on mongohq on their standard per gb plan.

like image 595
MonkeyBonkey Avatar asked May 06 '15 22:05

MonkeyBonkey


1 Answers

That means you're trying to read from a secondary node in a replica set, you can only read from the primary node by default.

You can allow a secondary node to accept reads by running rs.slaveOk() in a mongo shell that is connected to that secondary node. Allowing reads from a secondary is not recommended, because you could be reading stale data if the node isn't yet synced with the primary node.

UPDATE: As Janusz Slota's comment points out, rs.slaveOk() is no longer used. Use rs.secondaryOk() instead, however this is still not recommended. Here's the documentation for rs.secondaryOk().

like image 50
Nocturno Avatar answered Sep 18 '22 04:09

Nocturno