栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

MongoDB mongoose collection.find选项弃用警告

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MongoDB mongoose collection.find选项弃用警告

更新:

5.2.10已发布,可在此处下载。

使用

mongoose.set('useCreateIndex',true);
有mongooose调用
createIndex
上MongoDB的本地驱动程序的方法。

有关文档的更多信息,您可以查看页面
https://mongoosejs.com/docs/deprecations

有关此问题及其修复的更多信息,
请访问https://github.com/Automattic/mongoose/issues/6880

原始答案:

Mongoose 5.2.9版本将本机mongodb驱动程序升级到3.1.3,其中添加了一些更改,以在调用不赞成使用的本机驱动程序方法时引发警告消息。

fields
option已弃用,并由
projection
option 代替。

您将不得不等待猫鼬在其末端进行更改,以将场选项替换为投影。该修复程序计划于5.2.10发布。

您可以暂时返回5.2.8,它将取消所有弃用警告。

npm install mongoose@5.2.8

对于所有其他不建议使用的警告,您必须视情况而定。

使用其他收集方法时,您还会看到其他弃用警告。

DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findoneAndReplace or findoneAndDelete instead.DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.DeprecationWarning: collection.save is deprecated. Use insertOne, insertMany, updateOne, or updateMany instead.DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

findOne*
默认情况下,所有的mongoose写方法
findAndModify
都使用mongodb本机驱动程序中已弃用的方法。

用于

mongoose.set('useFindAndModify', false);
使mongooose
findOne*
在mongodb本机驱动程序上调用适当的方法。

对于

remove
和分别
update
delete*
update*
方法替换这些调用。

用于分别

save
insert*
/
update*
方法替换这些调用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/484801.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号