Skip to content

Instantly share code, notes, and snippets.

View stefandesu's full-sized avatar
🍁

Stefan Peters stefandesu

🍁
View GitHub Profile
@stefandesu
stefandesu / subs.md
Created October 4, 2023 17:39 — forked from tatsumoto-ren/subs.md
Japanese Subtitles
@stefandesu
stefandesu / README.md
Last active August 8, 2019 06:02
Mongoose: Automatically Reconnect

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 and reconnectInterval 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 () => {