Cannot save document after unsetting a property of an object in a Map
, then removing that object from the Map
#15108
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
8.9.1
Node.js version
22.8.0
MongoDB server version
8.0.4
Typescript version (if applicable)
No response
Description
If I have an object within a
Map
and set a property value in it toundefined
(to make mongoose unset it in the database), then proceed to remove that object from theMap
altogether, mongoose produces an update that triggers aMongoServerError
.With the reproduction code I get from
car.getChanges()
an update like{ '$unset': { 'owners.abc.name': 1, 'owners.abc': 1 } }
which then results in aUpdating the path 'owners.abc' would create a conflict at 'owners.abc'
MongoServerError
.Steps to Reproduce
Expected Behavior
I'd expect to get just
{ '$unset': { 'owners.abc': 1 } }
fromcar.getChanges()
and thesave()
to succeed afterwards.The text was updated successfully, but these errors were encountered: