node.js - Set field to empty for mongo object using mongoose -
i have document object has embedded sub-document. "clear" sub-document, try this:
obj.mysub = {}; obj.save(); this doesn't work, object still has contents of mysub sub-document. this:
obj.mysub = undefined; obj.save(); this work, removes sub-document object.
my question why doesn't first version work? going on in mongodb / mongoose in first example?
[edit] why doesn't empty object saved in first example above.
mongoose sort of "protects" lot of logic have presented in it's own internal resolution. if need @ lower level driver in:
yourmodel.update( { /*statement matching document query */ }, { "$unset": { "mysub": 1 } } ) and per normal mongodb logic work , remove level in document selected. see $unset operator more.
Comments
Post a Comment