You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under normal conditions there is an automatic type determination of timestamps.
constAdminModel=buildModel('10_admins','Admin',adminSchema);constadmin=awaitAdminModel.findOne();admin?.createdAt// It works
But as soon as I set statics or methods, timestamps related types are disabled.
constadminSchema=newSchema({// Fields},{statics: {// Some statics},timestamps: true});constAdminModel=buildModel('10_admins','Admin',adminSchema);constadmin=awaitAdminModel.findOne();admin?.createdAt// no createdAt attributes
But when I change the timestamps in DefaultSchemaOptions interface directly, it works again.
Is this by design or is there no definitive solution yet?
The text was updated successfully, but these errors were encountered:
We have an issue #12807 to track this issue, as a workaround you should define createdAt and updatedAt yourself in your schemas if you use statics, methods, or virtuals.
Prerequisites
Mongoose version
7.6.3
Node.js version
20.9
MongoDB version
7.0.2
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
ubuntu22.04
Issue
It may be related to this PR.
I wrote a model build function to make it easier for me to standardize the addition of plugins when building a model.
Model builder function:
Schema:
Under normal conditions there is an automatic type determination of timestamps.
But as soon as I set statics or methods, timestamps related types are disabled.
But when I change the timestamps in DefaultSchemaOptions interface directly, it works again.
Is this by design or is there no definitive solution yet?
The text was updated successfully, but these errors were encountered: