question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assignment in nested object not being saved - regression in 6.0.x

See original GitHub issue

Do 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
johnpebcommented, Jan 3, 2022

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.

0reactions
vkarpov15commented, Dec 26, 2021

@johnpeb the only place you should still need markModified in 6.x is if you’re modifying a path underneath a Mixed path.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested objects not working (in certain pattern) #724 - GitHub
The "An object inside an array of object" structure isn't presenting properly (both Example Values and Schema sections). Here is my code ...
Read more >
Object.assign—override nested property - Stack Overflow
Is there any ES6 way to only change the nested property, without loosing all the other, with Object.assign ? javascript · ecmascript-6 ·...
Read more >
6.1. Pipelines and composite estimators - Scikit-learn
Pipeline can be used to chain multiple estimators into one. This is useful as there is often a fixed sequence of steps in...
Read more >
Backbone.js
Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable ...
Read more >
Nested query | Elasticsearch Guide [8.5] | Elastic
The nested query searches nested field objects as if they were indexed as ... (Optional, Boolean) Indicates whether to ignore an unmapped path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found