不建议使用服务器发现和监视引擎 [英] Server Discovery And Monitoring engine is deprecated

查看:151
本文介绍了不建议使用服务器发现和监视引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Node.js应用程序中使用Mongoose,这是我的配置:

I am using Mongoose with my Node.js app and this is my configuration:

mongoose.connect(process.env.MONGO_URI, {
   useNewUrlParser: true,
   useUnifiedTopology: true,
   useCreateIndex: true,
   useFindAndModify: false
}).then(()=>{
    console.log(`connection to database established`)
}).catch(err=>{
    console.log(`db error ${err.message}`);
    process.exit(-1)
})

但是在控制台中它仍然会给我警告:

but in the console it still gives me the warning:

DeprecationWarning:不建议使用当前的服务器发现和监视"引擎,并将在以后的版本中将其删除.要使用新的服务器发现和监视"引擎,请将选项{useUnifiedTopology:true}传递给MongoClient构造函数.

DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

出什么问题了?我以前没有使用useUnifiedTopology,但是现在它显示在控制台中.我将其添加到配置中,但它仍会给我这个警告,为什么?我什至不使用MongoClient.

What is the problem? I was not using useUnifiedTopology before but now it shows up in the console. I added it to the config but it still gives me this warning, why? I do not even use MongoClient.

当Felipe Plets回答时,猫鼬存在问题,他们在更高版本中修复了该错误.因此,您可以通过更新猫鼬版本来解决问题.

As Felipe Plets answered there was a problem in Mongoose and they fixed this bug in later versions. So you can solve problem by updating mongoose version.

推荐答案

更新

猫鼬5.7.1已发布,并且似乎已解决了该问题,因此设置useUnifiedTopology选项可以按预期工作.

Mongoose 5.7.1 was release and seems to fix the issue, so setting up the useUnifiedTopology option work as expected.

mongoose.connect(mongoConnectionString, {useNewUrlParser: true, useUnifiedTopology: true});

原始答案

我遇到了同样的问题,因此决定深入研究猫鼬代码: https://github.com/Automattic/mongoose/search?q=useUnifiedTopology&unscoped_q=useUnifiedTopology

I was facing the same issue and decided to deep dive on Mongoose code: https://github.com/Automattic/mongoose/search?q=useUnifiedTopology&unscoped_q=useUnifiedTopology

似乎是Mongoose 5.7版上添加的一个选项,但尚未有充分的文档记录.我什至找不到它在库历史记录中提到的 https://github.com/Automattic/猫鼬/blob/master/History.md

Seems to be an option added on version 5.7 of Mongoose and not well documented yet. I could not even find it mentioned in the library history https://github.com/Automattic/mongoose/blob/master/History.md

根据代码中的注释:

  • @param {Boolean} [options.useUnifiedTopology = false]默认情况下为False.设置为true以选择加入MongoDB驱动程序的副本集和分片群集监视引擎.
  • @param {Boolean} [options.useUnifiedTopology=false] False by default. Set to true to opt in to the MongoDB driver's replica set and sharded cluster monitoring engine.

项目GitHub上也存在与此错误有关的问题: https://github.com /Automattic/猫鼬/问题/8156

There is also an issue on the project GitHub about this error: https://github.com/Automattic/mongoose/issues/8156

在我的情况下,尽管选项应该为false,但我不在副本集或分片群集中不使用Mongoose.但是如果为假,它会抱怨设置应该为真.一旦为真,它仍然不起作用,可能是因为我的数据库未在副本集或分片群集上运行.

In my case I don't use Mongoose in a replica set or sharded cluster and though the option should be false. But if false it complains the setting should be true. Once is true it still don't work, probably because my database does not run on a replica set or sharded cluster.

我已经降级为5.6.13,并且我的项目恢复正常.因此,我目前唯一的选择是将其降级,并等待更新更新.

I've downgraded to 5.6.13 and my project is back working fine. So the only option I see for now is to downgrade it and wait for the fix to update for a newer version.

这篇关于不建议使用服务器发现和监视引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆