'user in not getting updated after update query
here image - 1, I was trying to update data using the update query, but I'm getting an undefined message in log, I have passed the right id through postman form-data
User.updateOne({ _id:params.id},
{$set:{
name:params.name,
dob: new Date(params.dob),
dom: new Date(params.dom),
}
}, function (error, result) {
logger.info("#edit() : User updated successfully with results = {%j}", result,{});
console.log(result);
done(result);
});
}
Solution 1:[1]
Because query params id is a string, you need to use an Object id:
import {Types} from 'mongoose';
User.updateOne({ _id:new Types.ObjectId(params.id)},
{$set:{
name:params.name,
dob: new Date(params.dob),
dom: new Date(params.dom),
}
}, function (error, result) {
logger.info("#edit() : User updated successfully with results = {%j}", result,{});
console.log(result);
done(result);
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marco Bertelli |
