猫鼬失去联系Mongo Atlas副本集

时间:2019-04-08 14:29:35

标签: node.js mongoose mongodb-atlas

Ubuntu环境(Amazon Sao Pablo): Node.js:v10.15.3 猫鼬:v5.4.17

Db Atlas-副本集(Amazon Sao Pablo): mondoDb:4.0

在某些时候,猫鼬会断开连接,此后,它开始循环,断开连接,重新连接,断开连接,重新连接。.
我需要重新启动nodejs应用程序才能使其正常工作。

我已覆盖所有连接处理程序,仅用于记录事件。我要离开Moongose来管理重新连接。 这是我的配置。我玩过超时,useNewUrlParser值以及连接池。没有改变。几天后,我的产品环境崩溃了。

=iif(Fields!Factor.Value = 0.00,
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*CDbl(1),
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value) 
 mongo: {
    url: 'mongodb+srv://user:password@cluster.mongodb.net/xxxx?retryWrites=true',
     options: {
                useNewUrlParser: true,
                socketTimeoutMS: 60000

            }
        }
  mongoose.connection.on('connecting', function() {
        console.log(`MongodDB event CONNECTING - Connecting to Mongo ...`);
    });

    mongoose.connection.on('error', function(err) {
        console.log('MongodDB event ERROR - Could not connect to MongoDB');
        console.error(err);
        sendEmail(`MongoDB event ERROR on ${mongoose.connection.host} ${err.message}`);
    });

    mongoose.connection.on('disconnected', function(err) {
        console.log('MongodDB event DISCONNECTED - Lost MongoDB connection...');
        sendEmail(`MongoDB event DISCONNECTED from ${mongoose.connection.host}`);

    });

    mongoose.connection.on('connected', function(e) {
        console.log(
            `MongoDB event CONNECTED on ${mongoose.connection.host} - DB: ${
                mongoose.connection.name
            }. (Mongoose ${mongoose.version})`
        );
    });

    mongoose.connection.on('reconnected', function() {
        console.log(
            `MongoDB event RECONNECTED on ${mongoose.connection.host}. (Mongoose ${
                mongoose.version
            })`
        );

        sendEmail(`MongoDB reconnected to ${mongoose.connection.host}`);
    });

    mongoose.connection.on('fullsetup', function(e) {
        console.log(
            `MongoDB event FULLSETUP on ${mongoose.connection.host}. (Mongoose ${mongoose.version})`
        );

        sendEmail(`MongoDB event FULLSETUP to ${mongoose.connection.host}`);
    });

    mongoose.connection.on('all', function(e) {
        console.log(
            `MongoDB event ALL on ${mongoose.connection.host}. (Mongoose ${mongoose.version})`
        );

        sendEmail(`MongoDB event ALL to ${mongoose.connection.host}`);
    });

使用本地数据库实例(无副本)时,我们没有此问题。我不确定猫鼬是否可以处理副本连接。 Mongo Atlas支持建议对nodejs使用官方的mongodb驱动程序。

0 个答案:

没有答案