同时使用两个(node:63440)弃用警告:不建议使用当前URL字符串解析器和当前服务器发现和监视引擎

编程入门 行业动态 更新时间:2024-10-09 19:19:31

同时使用两个(node:63440)弃用警告:不建议使用当前URL<a href=https://www.elefans.com/category/jswz/34/1771434.html style=字符串解析器和当前服务器发现和监视引擎"/>

同时使用两个(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字符串解析器和当前服务器发现和监视引擎

本文发布于:2024-05-07 13:11:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   两个   建议   发现   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!