0

I learn mongoose on NodeJS and I wanted to use usefindOneAndUpdate, it works on db I have the updates but the response gives an error and I couldn't find why help me pls. code:

await userModel.findOneAndUpdate(
        { _id: req.params.id },
        {
            $set: {
                nickName: req.body.nickName,
            },
        },
        { upsert: true, new: true, setDefaultsOnInsert: true },
        (err, docs) => {
            if (!err) return res.send(docs);
            else return res.status(500).send({ message: err });
        }
    );
} catch (err) {
    return res.status(500).json({ message: err });
}

error:

"originalStack": "Error\n    at model.Query._wrappedThunk [as _findOneAndUpdate]

(C:\\Users\\alike\\Documents\\projetsJS\\chatApp-Node-React\\node_modules\\mongoose\\lib\\helpers\\query\\wrapThunk.js:25:28)
at C:\\Users\\alike\\Documents\\projetsJS\\chatApp-Node-React\\node_modules\\kareem\\index.js:279:20
at _next (C:\\Users\\alike\\Documents\\projetsJS\\chatApp-Node-React\\node_modules\\kareem\\index.js:103:16)
at C:\\Users\\alike\\Documents\\projetsJS\\chatApp-Node-React\\node_modules\\kareem\\index.js:508:38
at processTicksAndRejections (internal/process/task_queues.js:77:11)"

Edit: @GulshanAggarwal here is all the file https://i.stack.imgur.com/r4LCj.png

Shantanu Sharma
  • 666
  • 6
  • 21
Kenyuki
  • 65
  • 1
  • 7

0 Answers0