Reliably reconnect to MongoDB

后端 未结 7 871
佛祖请我去吃肉
佛祖请我去吃肉 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 20:01

    It's happening because it might have crossed the retry connection limit. After number of retries it destroy the TCP connection and become idle. So for it increase the number of retries and it would be better if you increase the gap between connection retry.

    Use below options:

    retryMiliSeconds {Number, default:5000}, number of milliseconds between retries.
    numberOfRetries {Number, default:5}, number of retries off connection.
    

    For more details refer to this link https://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html

    Solution:

    MongoClient.connect("mongodb://localhost:27017/integration_test_?", {
        db: {
          native_parser: false,
    retryMiliSeconds: 100000,
    numberOfRetries: 100
        },
        server: {
          socketOptions: {
            connectTimeoutMS: 500
          }
        }
      }, callback)
    
    0 讨论(0)
提交回复
热议问题