最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

(node:63208)不推荐使用DeprecationWarning:collection.ensureIndex。使用createIndexes而不是[复制]

运维笔记admin10浏览0评论

(node:63208)不推荐使用DeprecationWarning:collection.ensureIndex。使用createIndexes而不是[复制]

(node:63208)不推荐使用DeprecationWarning:collection.ensureIndex。使用createIndexes而不是[复制]

这个问题在这里已有答案:

  • MongoDB mongoose collection.find options Deprecation Warning 4个答案
回答如下:

问题是mongoose仍然使用collection.ensureIndex,并且应该在不久的将来由他们更新。要删除消息,可以使用package.json中的5.2.8版降级(并删除任何缓存,最后的方法是卸载它,使用npm install [email protected]安装它):

“mongoose”:“^ 5.2.8”

编辑:在编辑中,Mongoose现在是v5.4.13。根据他们的文档,这些是弃用警告的修复程序......

mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);

用updateOne(),updateMany()或replaceOne()替换update()

用deleteOne()或deleteMany()替换remove()。

将count()替换为countDocuments(),除非您想要计算整个集合中有多少文档(没有过滤器)。在后一种情况下,使用estimatedDocumentCount()。

发布评论

评论列表(0)

  1. 暂无评论