Inconstancy with .set("key", undefined)
in middlewares
#12155
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
6.4.1
Node.js version
16.14.2
MongoDB server version
4.2.3
Description
Depending on how you define your update payload, it will result in different behaviours in Query middlewares when you try to set some property to undefined with
this.set("key", undefined)
method.$set
: setting toundefined
have no effect and will use property value fromupdate
object$set
: setting toundefined
will effectively remove property value fromupdate
objectNB: I have not checked for Document middlewares but it could be the same.
Steps to Reproduce
Expected Behavior
I would expect that both usage of
query.set('key', undefined)
results in the same generated query update{ $set: {} }
.The text was updated successfully, but these errors were encountered: