mongoose findByIdAndUpdate - check field and modify it

385 Views Asked by At

I have the following code:

 Something.findByIdAndUpdate(
    req.query.id,
    { $inc: { available: -1 } },
    { new: true, useFindAndModify: false },
    (err, book) => {
  );
});

I want to update the available field only if it is greater than 0. I could look for the item check if its field is bigger than 0 and then if it, look for it again and update it. Is there a way to do this using only a function?

0

There are 0 best solutions below