mongodb连接警告修复

问题

Node.js中mongoose模块连接MongoDB数据库时提示(node:12580) 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.的解决方案

mongoose.connect('mongodb://localhost:27018/blog',function (err) {
if (err) {
console.log('数据库连接失败');
} else {
console.log('数据库连接成功');
app.listen(8099);
}
});

 

解决

mongoose.connect('mongodb://localhost:27018/blog',{ useNewUrlParser: true },function (err) {
if (err) {
console.log('数据库连接失败');
} else {
console.log('数据库连接成功');
app.listen(8099);
}
});

 

posted @ 2019-05-30 19:25  venkim  阅读(469)  评论(0编辑  收藏  举报