v8.8.3 save() on a model with discriminator misses nested schema timestamps #15088
Open
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Prerequisites
Mongoose version
8.8.3
Node.js version
v22.8.0
MongoDB server version
v7.0.0
Typescript version (if applicable)
No response
Description
I noticed that my subdocuments were missing timestamps on v8.8.3 but not v8.8.2.
Per the documentation, Mongoose should set
createdAt
when the document is first inserted, andupdatedAt
should be added/updated whenever you update the document using save(), updateOne(), updateMany(), findOneAndUpdate(), update(), replaceOne(), or bulkWrite().While trying to create a minimal reproducible example, I did notice that the presence of a discriminator on the top level schema is required to see the bug. I also noticed that when using
.save()
, the timestamps are not being updated, whereasupdateOne()
andfindByIdAndUpdate()
do update, even if I don't specify the discriminator field in theupdateOne()
filter. I did not test the other update operations.Steps to Reproduce
Try the sample code using v8.8.2 and then with v8.8.3. Notice that the last console log only has timestamps when using v8.8.2.
Sample code (omitted the mongoose import and DB connection):
However, if you comment out the discriminator on Request, then the timestamps do show up in both versions.
Appendix: I used the following to verify that the issue is present on
.save()
, but not withfindByIdAndUpdate
orupdateOne
. I did not exhaustively test other operators.Expected Behavior
I would expect that the behavior between v8.8.2 and v8.8.3 to be the same (include timestamps in subdocuments, even if the top level schema has discriminators), since there were no announced changes.
The text was updated successfully, but these errors were encountered: