Reliably reconnect to MongoDB

后端 未结 7 872
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 19:24

UPDATE: I am using the 2.1 version on the driver, against 3.2

I have a node application that uses MongoDB. The problem I have is that if the MongoDB

7条回答
  •  無奈伤痛
    2020-12-13 19:58

    With mongodb driver 3.1.10, you can set up your connection as

    MongoClient.connect(connectionUrl, {
        reconnectInterval: 10000, // wait for 10 seconds before retry
        reconnectTries: Number.MAX_VALUE, // retry forever
    }, function(err, res) {
        console.log('connected') 
    })
    

    You do not have to specify autoReconnect: true as that's the default.

提交回复
热议问题