i'm using findOneAndUpdate function from mongoose and in the nodejs i am updating a record now i want to send the updated data in response but as mongoose stop supporting callback function in updates now i have to do two request to mongo
first one to update the data and the another one to get the updated record ... like this
module.exports.addcontact = async (req, res) => {
await UserModel.findOneAndUpdate(
{ email: email },
{ $set: { number : req.bode.number } },
);
const data = await UserModel.findOne({ email: decode.email });
res.send({ stat: true, decode, wallets: data.Wallets });
}
Here first i'm updating the record and after that again finding it and storing in data variable to get the latest record after the updates made..
i want to know if it is possible to update the data and get the updated document in one time so dont have to apply multiple operation for one task only.