S
S
Stanislav2018-10-05 00:38:38
Mongoose
Stanislav, 2018-10-05 00:38:38

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 }
}

If p1 or p2 is updated during the update method, then the p3 field must be deleted
schema.pre('update', function(next) {
    this.updateOne({},{ $unset: { p3: !0 } })
    next()
})

Or is it not realistic to find out? And you have to do everything directly in the handler?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question