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替代

  

猜你喜欢

转载自www.cnblogs.com/Mr-Rshare/p/12592575.html
今日推荐