Pre validate: is not triggert on all sub documents when set via _.set() with a nested path #14591
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
8.3.4
Node.js version
v20
MongoDB server version
5.0
Typescript version (if applicable)
5.4.5
Description
If I have a multi nested document like this:
doc = {a: {b: {c: {d: {e: string} } } } }
And then I change a value via
await doc._set({'a.b.c.d.e': 'value'}).save()
the value is saved correctly in the nestede
subDocument. But during the saving process not all thepre('validate', () => ..)
hooks get triggered.Only on the first (
a
) and second subdocument (b
) the pre validate hook is triggered.Steps to Reproduce
Expected Behavior
For every variant I expected the following output:
This is indeed the output for variants 1, 2 and 3
But when using
doc.set({'a.b.c.d.e': 'updated nested value'})
, aka variant 4, the value is saved correctly but not all the pre validate hooks are triggered:I was expecting to see the following pre validate hooks get triggered as well:
The text was updated successfully, but these errors were encountered: