Node.js mongo db和nodejs中不推荐使用当前URL字符串解析器
我使用mongodb和nodejs 8连接到数据库,但出现以下错误:Node.js mongo db和nodejs中不推荐使用当前URL字符串解析器,node.js,mongodb,Node.js,Mongodb,我使用mongodb和nodejs 8连接到数据库,但出现以下错误: (node:7280) 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. 我的代码: mongo
(node:7280) 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(db,(err) => {
if (err)
console.error(err);
else
console.log("Connected to the mongodb");
});
将代码更改为:
mongoose.connect(db, {useNewUrlParser: true}, (err) => {
if (err)
console.error(err);
else
console.log("Connected to the mongodb");
});
出现此错误是因为您正在使用更新版本(>=4.0.0)的MongoClient如果它也失败,则需要向代码中添加
{useUnifiedTopology:true}
。它看起来像:
mongoose.connect(db, {useNewUrlParser: true, useUnifiedTopology: true }, (err) => {
if (err)
console.error(err);
else
console.log("Connected to the mongodb");
});
欢迎来到SO。看起来您可能忘记了在问题中包含您看到的错误。是的,这是真的,错误是:(节点:7280)弃用警告:当前URL字符串分析器已弃用,将在将来的版本中删除。要使用新的解析器,请将选项{useNewUrlParser:true}传递给MongoClient.connect.thank's Remembering的可能重复项