Mongodb connection with nodejs
I met this connection error when I restart mongodb using mongoose in nodejs.
connection error: { [DisconnectedError: Ran out of retries trying to reconnect to "127.0.0.1:27017". Try setting `server.reconnectTries` and `server.reconnectInterval` to something higher. ] message: 'Ran out of retries trying to reconnect to "127.0.0.1:27017". Try setting `server.reconnectTries` and `server.reconnectInterval` to something higher.', name: 'DisconnectedError' }
From: http://mongoosejs.com/docs/connections.html
Note: If auto_reconnect is on, mongoose will give up trying to reconnect after a certain number of failures. Set the
server.reconnectTries
andserver.reconnectInterval
options to increase the number of times mongoose will try to reconnect.
// Good way to make sure mongoose never stops trying to reconnectmongoose.connect(uri, { server: { reconnectTries: Number.MAX_VALUE } });