I have a simple document with name (require), description (optional). In my model, I update a document with a valid id and I pass description with value undefined because I
If someone does not want to drop down to native driver, refer to this answer https://stackoverflow.com/a/54320056/5947136
The issue here is using type as a key in Schema.
var schema = new Schema({
name: {
required: true,
set: mongooser.trimSetter,
trim: true,
type: String, // <-- This is causing the issue
unique: true
},
description: {
set: mongooser.trimSetter,
trim: true,
type: String // <-- This is causing the issue
}
});
Refer the above answer for a solution without the need for native driver.
Try dropping down to the native driver like so:
var update = function (model, callback) {
RoleSchema.update({_id: model.id}, {$unset: {description: 1 }}, callback);
});
};