【问题标题】:(node: 15702) How to remove DeprecationWarning on Node.js?(节点:15702)如何删除 Node.js 上的 DeprecationWarning?
【发布时间】:2020-01-17 08:52:39
【问题描述】:

我在使用 Node.js 时在我的 shell 上收到一条弃用警告消息。它开始出现在我的项目中间,我不知道如何摆脱它......

我已经安装了 Axios、Express 和 Mongoose 作为依赖项。这就是我的 package.json 的样子:

{
  "name": "backend",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon src/index.js"
  },
  "dependencies": {
    "axios": "^0.19.1",
    "express": "^4.17.1",
    "mongoose": "^5.8.7"
  },
  "devDependencies": {
    "nodemon": "^2.0.2"
  }
}

这是终端上显示的内容:

yarn run v1.17.0
$ nodemon src/index.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/index.js`
(node:15702) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

有谁知道如何摆脱贬低警告?

(node:15702) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

谢谢!

【问题讨论】:

    标签: node.js mongodb express mongoose axios


    【解决方案1】:

    我找到了解决办法。添加了 => useCreateIndex: true,(就像一个魅力)。

    mongoose.connect('mongodb+srv://<user>:<password>@cluster0-h2xcd.mongodb.net/<project>?retryWrites=true&w=majority', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex: true,
    });
    

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多