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

 

相关文章:

  • 2021-12-25
  • 2021-09-16
  • 2021-11-26
  • 2021-10-06
  • 2021-09-03
  • 2022-12-23
  • 2021-10-29
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-05-19
  • 2021-06-03
相关资源
相似解决方案