Automattic / Automattic/mongoose

Embedded document .save() not persisting

Open
#2,210 11 comments 0 reactions 0 assignees View on GitHub
discussion enhancement
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 7h
Merged PRs (30d)
35

Description

See gist: https://gist.github.com/xizhao/6ba5bc02229ba0e8eb48

When I try to save Child it passes with no error and looks like it saved, but it doesn't persist in the db.

I am pushing data to an array in the embedded schema via a method bound to the embedded schema. markModified does not help. Using doc.__parent.save() does work, however.

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in the linked gist and compare saving the embedded Child with saving its parent via __parent.save(). Trace the embedded schema's save behavior and markModified usage, then add a regression test showing whether array changes persist after Child.save().

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.