Home > Back-end >  Mongoose get all value where balance is negative
Mongoose get all value where balance is negative

Time:09-27

I am trying to get all data from a collection where balance is negative.

let data = await Model.find({ subStaffType: 3, balance < 0  })

CodePudding user response:

You can use the MongoDB less than query operator.

let data = await Model.find({ subStaffType: 3, balance: { $lt: 0 })

I advice you to read the MongoDB documentation first and get acquainted with the various query operators. Mongoose is a wrapper for the native MongoDB driver, so the query syntax and the supported operators are the same.

  • Related