@Schema({
timestamps: {
currentTime: () => Date.now(), // 根据官方文档写法
},
})
export class Schema extends Document {
...
@Prop()
createdAt: number; // 需要修改类型为number才生效
@Prop()
updatedAt: number; // 需要修改类型为number才生效
}
export const MySchema = SchemaFactory.createForClass(Schema);
![](https://cdn.bg7zag.com/wp-content/uploads/2023/09/1695278247-mongoose_20230921143350.png)
![](https://cdn.bg7zag.com/wp-content/uploads/2020/10/1603352118-weixin.png)