Node.js 同时出现两个(节点:63440)弃用警告:当前URL字符串解析器和当前服务器发现和监视引擎已弃用

Node.js 同时出现两个(节点:63440)弃用警告:当前URL字符串解析器和当前服务器发现和监视引擎已弃用,node.js,mongoose,Node.js,Mongoose,任何人都知道这两个弃用警告的解决方法: (node:63440) DeprecationWarning: current URL string parser is deprecated, and wi ll be removed in a future version. To use the new parser, pass option { useNewUr lParser: true } to MongoClient.connect. (node:63440)

任何人都知道这两个弃用警告的解决方法:

   (node:63440) DeprecationWarning: current URL string parser is deprecated, and wi
    ll be removed in a future version. To use the new parser, pass option { useNewUr
    lParser: true } to MongoClient.connect.
    (node:63440) DeprecationWarning: current Server Discovery and Monitoring engine
    is deprecated, and will be removed in a future version. To use the new Server Di
    scover and Monitoring engine, pass option { useUnifiedTopology: true } to the Mo
    ngoClient constructor.
产生错误的代码最初是这样的:

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fruitsDB');
但是,当我试图通过传递{userNewUrlParser:true}来修复它时,它对第一次弃用有效,但第二次弃用仍然存在,如果我传递了所有两次,代码将完全中断 我试过:

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fruitsDB', { useNewUrlParser: true });
这修正了第一个反对意见,我也试过了

mongoose.connect('mongodb://localhost:27017/fruitsDB', { useUnifiedTopology: true });
这修复了第二次去润滑,但我不知道如何修复我试过的两次

mongoose.connect('mongodb://localhost:27017/fruitsDB', { useNewUrlParser: true },{ useUnifiedTopology: true });
这完全毁了我的应用程序 我在pc上安装了mongodb v4.2.5版,对package.json的依赖关系如下:

 "dependencies": {
    "express": "^4.17.1",
    "lodash": "^4.17.15",
    "mongodb": "^3.5.7",
    "mongoose": "^5.9.13",
    "nodemon": "^2.0.3"
  }

我在Mongoclient上一次修复了多个弃用,即使用 猫鼬。set('whatever',true); 至于我在修复之前提出的问题是:

const mongoose = require('mongoose');
mongoose.set('useNewUrlParser', true);
mongoose.set('useUnifiedTopology', true);
mongoose.connect('mongodb://localhost:27017/fruitsDB');
第一行填充将修复第一个错误,第二行将修复第二个错误

mongoose.connect("mongodb://localhost:27017/fruitsDB",{ 
    useNewUrlParser: true ,
    useUnifiedTopology: true
});

试试这个

我觉得这样更好