-
- Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
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 aMap and set a property value in it to undefined (to make mongoose unset it in the database), then proceed to remove that object from the Map altogether, mongoose produces an update that triggers a MongoServerError.
With the reproduction code I get from car.getChanges() an update like { '$unset': { 'owners.abc.name': 1, 'owners.abc': 1 } } which then results in a Updating the path 'owners.abc' would create a conflict at 'owners.abc' MongoServerError.
Steps to Reproduce
const CarSchema = new mongoose.Schema({ owners: { type: Map, of: { name: String, }, }, }); const CarModel = mongoose.model('Car', CarSchema); const car = await CarModel.create({ owners: { abc: { name: 'John' } }, }); car.owners.get('abc').name = undefined; car.owners.delete('abc'); await car.save();Expected Behavior
I'd expect to get just { '$unset': { 'owners.abc': 1 } } from car.getChanges() and the save() to succeed afterwards.
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.