node-mongoose开发中常见警告或问题-持续更新


1. findOneAndUpdate、findOneAndDelete  不成功问题

  `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated.

  原因: findOneAndUpdate 和 findOneAndDelete 内部使用会findAndModify驱动,此驱动即将废除,所以提示警告。

  解决办法: 在mongoose连接时设置如下:useFindAndModify: false  

  

  可以参考官网解释:https://mongoosejs.com/docs/deprecations.html#-findandmodify-

 

2. collection.count 问题

  DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead

  原因:collection.count 在未来版本即将废除, 使用collection.countDocuments替代

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM