用下面这段代码连接MongoDB数据库出现了警告提示:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
警告提示:
(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.
更改为一下代码即可:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', { useNewUrlParser: true }, (err,res) => {
if (!err) {
console.log('连接数据成功!')
} else {
console.log('连接数据失败!');
}
})