zoukankan      html  css  js  c++  java
  • mongoose 报错 scheduleTimeoutControl MongoError: command find requires authentication

    可能原因是 mongoose 版本和mongodb 数据库版本不匹配,https://mongoosejs.com/docs/compatibility.html

    我再mongose 升级后报错 MongoTimeoutError: Server selection timed out after 30000 ms

    查了好多资料都不行,后来索性新建了一个项目只有链接数据库,居然可以没有报错.

    想想区别就是app.js 里面引用了别的东西,一行一行注销测试发现和 "excel-export""^0.5.1" 不兼容

    所以报这个错可以研究下是不是和别的东西不兼容

    贴下我mongoose@5.7.0的链接代码

    import mongoo = require('mongoose');
    import config = require('../config');

    // 设置连接池数量,并且超过后自动销毁
    // auth,user,password
    const options = {
        poolSize: 100,
        auto_reconnect: true,
        autoReconnect:true,
        keepAlive: 10,
        useNewUrlParser: true,
        useUnifiedTopology:true,
        reconnectTries: Number.MAX_VALUE// 总是尝试重新连接
        reconnectInterval: 500// 每500ms重新连接一次
        bufferMaxEntries: 0,
        connectTimeoutMS: 99999 // 99s后放弃重新连接
    };
    mongoo.set('useCreateIndex'true)
    // 连接数据库
    mongoo.connect(config.connectionoptions, (err=> {
        if (err) {
            console.log('Connection Error:' + err);
        } else {
            console.log('Connection success!');
        }
    });

    const db = mongoo.connection;
     
    db.on('error', (err=> {
        console.log('mongoose connection error:' + err);
        mongoo.disconnect();
    });
     
    db.once('open', (err=> {
        if (err) {
            console.log('Mongoose open Error:' + err);
        } else {
            console.log('Mongoose open success!');
        }
    });

    db.on('connecting'function() {
        console.log('connecting to MongoDB...');
    });

    db.on('connected'function() {
        console.log('MongoDB connected!');
    });

    db.on('reconnected'function () {
        console.log('MongoDB reconnected!');
    });

    db.on('disconnected'function() {
        console.log('MongoDB disconnected!');
        // 连接数据库
        mongoo.connect(config.connectionoptions, (err=> {
            if (err) {
                console.log('Connection Error:' + err);
            } else {
                console.log('Connection success!');
            }
        });
    });

    module.exports = mongoo;






  • 相关阅读:
    Cocos2d-x3.0游戏实例之《别救我》第四篇——乱入的主角
    TRIZ系列-创新原理-21-高速通过原理
    “cvSnakeImage”: 找不到标识符
    21世纪创业与知识之间的辩证关系
    Android导航栏ActionBar的具体分析
    HDU4565 && 2013年长沙邀请赛A题
    从切比雪夫不等式到大数定理
    在线笔试琐碎
    在线笔试琐碎
    算法求解中的变量、数组与数据结构(STL 中的容器)
  • 原文地址:https://www.cnblogs.com/aroundight/p/15068354.html
Copyright © 2011-2022 走看看