首页 > 数据库技术 > 详细

解决 mongoose DeprecationWarning 错误导致数据库连接不成功

时间:2020-04-21 09:41:59      阅读:81      评论:0      收藏:0      [点我收藏+]

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

 

解决 mongoose DeprecationWarning 错误导致数据库连接不成功

原文:https://www.cnblogs.com/baiyygynui/p/12742408.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!