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

I just want to fetch the barcodes field but It is giving an error.

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

I have also installed MongoDB nodejs driver:

"mongodb": "^3.6.3",

How to use .project() for minimizing the bandwidth by reducing the number of fields on return.

Ibad Shaikh
  • 2,704
  • 3
  • 15
  • 27

1 Answers1

3

if you are using simple find command you don't need project:

db.RentedProducts.find({customer: req.params.id}, {barcodes: 1, _id: 0 })
eshirvana
  • 23,227
  • 3
  • 22
  • 38