NodeJs MongoDB call Model.findOneAndUpdate() inside a Model.create()

Viewed 32

I want to execute an update query where I need the _id of the document I just created with a Model.create(). This is what I do, it doesn't give any error. It creates the document but it doesn't execute the findOneAndUpdate. I think I'm not doing it correctly

exports.createBill = async function (b) {
  return new Promise((resolve, reject) => {
    Bills.create(b, function (err) {
      if (err) {
        reject(err);
      } else {
        Calendar.findOneAndUpdate(
          { _id: b.rentalId },
          { id_fatturazione: b._id },
          function (err, results) {}
        );
        resolve();
      }
    });
  });
};
0 Answers
Related