首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(节点: 15702)如何删除DeprecationWarning上的Node.js?

问(节点: 15702)如何删除DeprecationWarning上的Node.js?
EN

Stack Overflow用户
提问于 2020-01-17 00:46:53
回答 1查看 4.2K关注 0票数 0

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

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

代码语言:javascript
复制
{
  "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"
  }
}

这就是航站楼上显示的内容:

代码语言:javascript
复制
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.

有谁知道如何去除脱毛警告吗?

代码语言:javascript
复制
(node:15702) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-01-17 00:52:39

我找到解决办法了。增加了=> useCreateIndex:真, (工作得很有魅力)。

代码语言:javascript
复制
mongoose.connect('mongodb+srv://<user>:<password>@cluster0-h2xcd.mongodb.net/<project>?retryWrites=true&w=majority', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59779797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档