Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js mongo db和nodejs中不推荐使用当前URL字符串解析器_Node.js_Mongodb - Fatal编程技术网

Node.js mongo db和nodejs中不推荐使用当前URL字符串解析器

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

我使用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.
我的代码:

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的可能重复项