Answer the question
In order to leave comments, you need to log in
Is it possible in mongoose schema to know which field is being updated?
It is necessary to create conditions in which the field was deleted when updating the fields of the document.
For example, there are 3 fields in the document
{
p1: { type: String }
p2: { type: String }
p3: { type: String }
}
schema.pre('update', function(next) {
this.updateOne({},{ $unset: { p3: !0 } })
next()
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question