【问题标题】:mongoose find on a closed connection not returning any result猫鼬在关闭的连接上找到不返回任何结果
【发布时间】:2020-10-04 05:10:04
【问题描述】:

myFunc() 由计时器每分钟触发一次。 find() 不执行回调第二次触发。我预计至少会出错

function myFunc() {
    let users = schemaMap.get('users');
    users.find({}, function (err, docs) {
        if(err) logger.error(err);
        logger.info('Mongo users: '+docs);
        mongoose.connection.close();
        //mongoose.disconnect();
    });
    ...
}

【问题讨论】:

标签: mongoose


【解决方案1】:

Mongoose 将queue up collection actions 直到连接打开。

如果要禁用命令缓冲:

mongoose.set('bufferCommands', false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-16
    • 2020-12-16
    • 2023-04-11
    • 2014-05-30
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    相关资源
    最近更新 更多