Search code examples
mongodbnode.jsshutdown

How to turn off Mongo (in Replica Set) properly without DB down?


My server set up is like that:

2 x Servers . The mongoDB has replica set among both servers. Each is one node.

and then I have my node.js server connect to the MongoDB.

What happen was.. when I kill the secondary server. (shutting down the server). The MongoDB at primary still up but the Node.js Server had connection issue with MongoDB then. Even I added the server back, it didn't work. I use mongoose and connect-mongo .

So, what happened? how to shut down Mongo node properly?


Solution

  • If your primary is still primary after you take down the secondary, it's a node's driver issue. Anyway you always should have an arbiter with an even number of replica nodes, the "why" is well documented on mongodb's doc.

    In case this is a node.js issue, wich version of node-mongodb-native are you using ? I had some different replicaset issues 2 month ago but there have ben fixed with the latest versions. The last replicaset issue of the driver has ben closed the 9th Sept, you shoud giv it a try with the last tagged version (V0.9.6.18 as i'm writing this)