Keystion的小博客

mongoose 连接 MongoDB 数据库的 useNewUrlParser 警告解决办法

useNewUrlParser

用下面这段代码连接MongoDB数据库出现了警告提示:

1
2
3
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/test');

警告提示:

1
(node:10626) 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.

更改为一下代码即可:

1
2
3
4
5
6
7
8
9
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/test', { useNewUrlParser: true }, (err,res) => {
if (!err) {
console.log('连接数据成功!')
} else {
console.log('连接数据失败!');
}
})
Keystion wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
来一杯咖啡~
Keystion WeChat Pay

微信打赏

Keystion Alipay

支付宝打赏