zoukankan      html  css  js  c++  java
  • 解决 mongoose DeprecationWarning 错误导致数据库连接不成功

    mongoose 版本低提示错误为:

    DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

    通常升级 mongoose 就可以解决:

    npm install mongoose


    连接数据库参数缺失提示错误:

    DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

    通常根据错误信息提示,将 useNewUrlparser 添加到 mongoose.connect 即可:

    // db
    const db = "mongodb://localhost:27017/blog";
    mongoose.Promise = global.Promise
    mongoose.connect(db, { useNewUrlParser: true }).then(() => console.log('Database Successful!')).catch((err) => console.log(err));
  • 相关阅读:
    BZOJ 1003 物流运输
    549565
    26566
    68
    554554
    5656
    49886
    5989
    6898
    656
  • 原文地址:https://www.cnblogs.com/baiyygynui/p/12742408.html
Copyright © 2011-2022 走看看