Assignment in nested object not being saved - regression in 6.0.x
See original GitHub issueDo you want to request a feature or report a bug?
Bug - regression from 5.11.13 to 6.0.12
What is the current behavior?
This code worked in 5.11.13 and prior. The test breaks in 6.0.12.
If the current behavior is a bug, please provide the steps to reproduce.
It’s hard to provide a standalone reproduction but here is the gist of the issue:
const orders = Order.find(...)
[..]
const order = orders[i]
[..]
const match = order.cumulativeConsumption.find(o => [..])
match.unit = 'foo'
match.value = 123
Debugging this in 6.0.12:
match.modifiedPaths()
(3) ['materialId', 'value', 'unit']
order.modifiedPaths()
(7) ['timing', 'timing.type', 'changeover', 'plannedStart', 'idle', 'plannedEnd', 'demand']
Note that cumulativeConsumption
is not in order
’s modified paths which I think is the reason that the update value is not saved
What is the expected behavior?
When order
is saved it should reflect the new value.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.
In mongoose 5.11.13 (and prior) the new value is saved. In 6.0.12 (and some previous versions of 6) this test fails. MongoDB: v4.2.8 Node: v12.22.7
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
I’ve not yet been able to reproduce but in testing I found https://github.com/Automattic/mongoose/issues/11172.
Working around the above bug (saving regardless of isModified) saves correctly in my test case but not in my application so there is something different going on for this issue - I will continue to try to reproduce after some feedback on the above bug.
@johnpeb the only place you should still need markModified in 6.x is if you’re modifying a path underneath a Mixed path.