用下面这段代码连接MongoDB数据库出现了警告提示:
js
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
警告提示:
bash
(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.
更改为一下代码即可:
js
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', { useNewUrlParser: true }, (err,res) => {
if (!err) {
console.log('连接数据成功!')
} else {
console.log('连接数据失败!');
}
})
文章信息
- 文章标题:mongoose 连接 MongoDB 数据库的 useNewUrlParser 警告解决办法 - Keystion
- 文章链接:https://webclown.net/posts/mongoose-连接-MongoDB-数据库的-useNewUrlParser-警告解决办法.html
- 版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。
- 转载请注明来自 Keystion !
markdown
[mongoose 连接 MongoDB 数据库的 useNewUrlParser 警告解决办法 - Keystion](https://webclown.net/posts/mongoose-连接-MongoDB-数据库的-useNewUrlParser-警告解决办法.html)