字符串解析器和当前服务器发现和监视引擎"/>
同时使用两个(node:63440)弃用警告:不建议使用当前URL字符串解析器和当前服务器发现和监视引擎
任何人都知道这两种弃用警告的解决方法:
(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上一次获得了关于多个弃用的修复程序,这是使用mongoose.set('whatever',true);至于我在修复之前提出的问题是:
const mongoose = require('mongoose');
mongoose.set('useNewUrlParser', true);
mongoose.set('useUnifiedTopology', true);
mongoose.connect('mongodb://localhost:27017/fruitsDB');
第一行填充可修复第一个错误,第二行将修复第二个错误
更多推荐
同时使用两个(node:63440)弃用警告:不建议使用当前URL字符串解析器和当前服务器发现和监视引擎
发布评论