I have this code
var ClientSchema = new Schema({
name: {type: String, required: true, trim: true}
});
var Client = mongoose.mode(\'Client\', ClientSchema)
exports.updateGroup = (request, response, next) => {
const requestObj = request.body;
var conditions = {
_id: request.body._id,
communityId: request.body.communityId
};
var newValues = {
$set: requestObj
};
Group.updateOne(conditions, newValues, { ***runValidators: true*** }, (err, group) => {
if (err) return response.json({
message: "Updation of group failed",
error: err,
status: 500
});
response.json(group);
});
};
You need to add { runValidators: true } as the third argument for validation to work on update.