LearnBoost/mongoose — Issue #603: Mongoose Fails to Detect Primary Switching to Secondary
Author: joemccann
Created: 2011-11-08 22:12:41+00:00
State: open

Recently, a team I'm currently working with has been using Mongoose 2.3.10 and when the db admin switches the primary to a secondary thus making a previous secondary the new primary, mongoose does not pick it up (we issue a simple read and get back an error

Is there an event mongoose can listen for to detect when a primary is not longer the primary?

Restarting the node app entirely detects the new primary with no problem, just FYI.

```
{
stack: "MongoError
at [object Object].wrap (code/colab-rest-api/node_modules/mongodb/lib/mongodb/db.js:798:11)
at [object Object]. (code/colab-rest-api/node_modules/mongodb/lib/mongodb/collection.js:775:31)
at [object Object].emit (events.js:67:17)
at [object Object]. (code/colab-rest-api/node_modules/mongodb/lib/mongodb/connections/repl_set_servers.js:286:113)
at [object Object].emit (events.js:64:17)
at Socket. (code/colab-rest-api/node_modules/mongodb/lib/mongodb/connection.js:222:16)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:678:14)
at IOWatcher.onReadable [as callback] (net.js:177:10)"
name: "MongoError"
documents: -[
-{
$err: "not master and slaveok=false"
code: 13435
}
]
requestId: 136941
responseTo: 4
responseFlag: 2
cursorId: "0"
startingFrom: 0
numberReturned: 1
}
```