We had some trouble with the automatic reconnect in Mongoose. In particular, the available options reconnectTries
and reconnectInterval
are applied when another HTTP request came in, not after the connection dropped (as I would have expected). This is the solution I came up with (basically adapted and extended from this:
-
Keep
reconnectTries
andreconnectInterval
low (but they don't really matter much in this solution anyway). -
Use something like the following for connecting to the database:
// Database connection
const mongoose = require("mongoose")
const connect = async () => {