Array SubDocs don't save on `document.save()`
See original GitHub issueIt seems that array subdocs don’t save on top-level document.save()
. They only persist their changes on findOneAndUpdate
/findByIdAndUpdate
/ any update operation that bypasses document validation, and only when using $set
.
Here’s a repo to reproduce:
https://github.com/varunjayaraman/mongoose-save-array-bug/tree/master
Edit: Sorry, forgot to mention This error occurred on v4.6.0
and v4.5.2
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mongoose doesn't save nested sub documents - Stack Overflow
I need to save some sub documents in a schema which is sub document of a schema. The save function is this: exports.add...
Read more >Mongoose v6.8.1: SubDocuments
Subdocuments have save and validate middleware just like top-level documents. Calling save() on the parent document triggers the save() middleware for all ...
Read more >Mongoose 101: Working with subdocuments - Zell Liew
The easiest way to update subdocuments is: Use findOne to find the document; Get the array; Change the array; Run save. For example,...
Read more >Accidentally Clicked "Don't Save" in Microsoft WordIntegris
Accidentally clicked "don't save" in Microsoft Word: Four Options to Help Find Unsaved Documents By Integris.
Read more >Mongoose 101: An Introduction to the Basics, Subdocuments ...
Let's say we want to save two things into the database: ... findOne : Gets one document. find : Gets an array of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve had a similar problem in the past and managed to solve it by marking that property as modified using:
@numbergames basically change detection on modifying array indexes using something like
parentDoc.subDoc[index] = value
won’t work. You have to usedocument.set()
instead