• 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;






  • 相关阅读:
    前端框架搭建
    npm的镜像和淘宝互换
    grunt,gulp,webpack前端打包工具的特性
    react 文章
    大数据学习08_HDFS2
    大数据学习07_HDFS1
    大数据学习06_zookeeper3_javaAPI操作
    大数据学习05_zookeeper2
    大数据学习04_zookeeper1
    大数据学习03_Linux集群搭建_辅助工具的安装
  • 原文地址:https://www.cnblogs.com/aroundight/p/15068354.html
Copyright © 2020-2023  润新知