【问题标题】:Mongoose warns: DeprecationWarning: current Server Discovery and Monitoring engine is deprecated?Mongoose 警告:DeprecationWarning:当前的服务器发现和监控引擎已弃用?
【发布时间】:2020-02-22 03:10:37
【问题描述】:

启动我的应用程序时,我收到以下警告:

(node:11800) 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.

然而我们正在指定这个值:

connection = await mongoose.connect(dbUrl, {
  keepAlive: true,
  useNewUrlParser: true,
  useCreateIndex: true,
  useFindAndModify: false,
  useUnifiedTopology: true
});

dbUrl 的值为:mongodb://localhost:27017/test-app

环境:

  • mongo v4.0.13 on macOS
  • nodejs v10.15.3
  • package mongodb@3.3.2
  • package mongoose@5.7.0

关于如何处理警告的任何想法?

【问题讨论】:

  • 我认为这是在这里讨论过的:stackoverflow.com/questions/57895175/…
  • 除了上面提到的链接,它拥有一切。您可以尝试通过mongoose.set('useUnifiedTopology', true); 明确设置
  • 原来问题与我们测试中的一段代码有关,该代码直接使用 mongodb 包来删除数据库。我们需要确保参数在那里传递。

标签: node.js mongodb mongoose


【解决方案1】:

这是由于公共 IP 地址的更改而发生的 对我有用的唯一方法是在 mongodb atlas 中更改我的公共 IP 地址 转到集群>网络访问>单击编辑 然后用你当前的公共IP地址更改IP地址

检查你的IP地址在谷歌上输入我的公共IP地址并点击第一个链接

【讨论】:

    【解决方案2】:

    这对我来说很好,没有更多错误。

    试试这个,

    mongoose
        .connect(db,{
            useUnifiedTopology: true,
            useNewUrlParser: true,
            })
        .then(() => console.log('MongoDB Connected...'))
        .catch(err => console.log(err));
    

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 2020-04-26
      • 2020-01-13
      • 2022-01-04
      • 2020-08-25
      • 2020-01-22
      • 2019-01-25
      • 2017-03-24
      • 1970-01-01
      相关资源
      最近更新 更多