如何解决在更新时不更新使用带有Nestjs的时间戳
我正在将NestJs用于一个后端项目,并试图使用时间戳来显示更新和创建日期,但是什么也没有显示!
@Schema()
export class Camera extends Document{
// @Prop({required: true,unique: true})
@Prop({required: true})
facility_name: string;
@Prop({required: true,unique : true})
camera_id: string;
@Prop({required: true})
camera_location: string;
@Prop({required: true})
camera_type: string;
@Prop({default : false})
is_deleted : boolean;
@Prop()
timestamps: true;
}
export const cameraSchema = SchemaFactory.createForClass(Camera); }
我该如何使用带有时间戳的frmawork时间戳,因为它没有显示任何日期!
解决方法
@Schema装饰器接受模式选项对象作为参数:
@Schema({
timestamps: true,})
使用此选项,会将 createdAt 和 updatedAt 属性添加到集合的文档中:
{
"_id": "5fc3fab191c59905a0931df2","content": "Lorem ipsum dolor sit amet","createdAt": "2020-11-29T19:46:57.199Z","updatedAt": "2020-11-29T19:46:57.199Z","__v": 0
}
在https://mongoosejs.com/docs/guide.html#options上查看有关所有选项的扩展信息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。