I'm trying to set up the MongoDB auto reconnection feature via Mongoose. Every way that I have tried to pass the option has had no effect, or at least the reconnected
event isn't being emitted.
What I've tried:
mongoose.createConnection("mongodb://localhost:27017/test", { auto_reconnect: true });
mongoose.createConnection("mongodb://localhost:27017/test", { autoReconnect: true });
mongoose.createConnection("mongodb://localhost:27017/test", { server: { auto_reconnect: true } });
mongoose.createConnection("mongodb://localhost:27017/test", { server: { autoReconnect: true } });
If one of these is correct, the reconnected
event should be triggered and a message should be logged in the console, however this never happens.
If there is a delay before the reconnection, does anyone know how to configure it?
Thanks in advance
For anyone looking into this, take a look at this and this issue in mongoose repository.
reconnected
event, and are you simulating an actual reconnect situation?createConnection()
call. My events are working normally with theconnected
/disconnected
events.mongoose.connect()
and notcreateConnection()
, perhaps that makes a difference)