Wrong document updating after pulling embedded object with _id
field alias
#9319
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Inconsistent object saving after
.pull(id)
if you disable_id
in the scheme of the subfield (MongooseArray
) and use another field that has an alias_id
.If the current behavior is a bug, please provide the steps to reproduce.
There problem is here.
What is the expected behavior?
Objects
parent
,parent_1
andparent_2
should be equal.Possible solutions:
Solution 0 (just hotfix)
Change this line
with
Solution 1 (bad)
Make
.pull
to mark all array as modified like.shift()
,.pop()
etc.Solution 2 (not so bad)
Make
.pull
to mark all array as modified if last element was removed.Solution 3 (better)
Make
.pull
to understand that pathType of_id
is notreal
butvirtual
(or maybe new onealias
) and should use smth likeModel.translateAliases()
Solution 4 (also not bad)
Allow to set option
_id
with field alias for Subschemas. Example:What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: