不推荐使用服务器发现和监控引擎 [英] Server Discovery And Monitoring engine is deprecated

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

问题描述

我在 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:

弃用警告:当前的服务器发现和监控引擎已弃用,并将在未来版本中删除.要使用新的服务器发现和监控引擎,请将选项 { 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 回答的那样,Mongoose 存在一个问题,他们在以后的版本中修复了这个错误.所以你可以通过更新猫鼬版本来解决问题.

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.

推荐答案

更新

Mongoose 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});

原答案

我面临同样的问题并决定深入研究 Mongoose 代码: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/自动/猫鼬/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/mongoose/issues/8156

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

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

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天全站免登陆