TypeError: Model.find(...).project is not a function

TypeError: Model.find(...).project is not a function

let totalProducts = await RentedProducts.find({
  customer: req.params.id,
}).project({ barcodes: 1 })

我只想获取条形码字段,但出现错误。

TypeError: RentedProducts.find(...).project is not a function

我也安装了MongoDB nodejs驱动:

"mongodb": "^3.6.3",

如何使用 .project() 通过减少 return 上的字段数来最小化带宽。

如果您使用的是简单的查找命令,则不需要项目:

db.RentedProducts.find({customer: req.params.id}, {barcodes: 1, _id: 0 })