This is my controller:
const updateUser = async (req, res) => {
const uid = req.params.uid
const updates = req.body
console.log(updates)
const status = await dao.updateUser(uid, updates)
res.json(status)
}
This is my dao:
export const updateUser = async (uid, userUpdates) => {
await usersModel.updateOne({ _id: uid }),
{ $set: userUpdates }
}
This is what I sent in the json body (as the userUpdates):
{
"username": "hihi",
"password": "chloe123",
"firstName": "chloe",
"lastName": "hu",
"email": "123456@gmail.com",
"dob": "2022-12-05",
"phone": "000-000-0000",
"type": "STUDENT"
}
I searched this error, what I sent is an object, not a new model, so I confused why this error still happened, since if it is an object, it will not automatically create a _id, I am wondering how this should be solved. Thanks!