TAM*_*M.G 5 timestamp mongodb 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); }
Run Code Online (Sandbox Code Playgroud)
我如何在 frmawork 中使用时间戳,因为它不显示任何日期!
小智 17
@Schema 装饰器接受模式选项对象作为参数:
@Schema({
timestamps: true,
})
Run Code Online (Sandbox Code Playgroud)
使用此选项,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
}
Run Code Online (Sandbox Code Playgroud)
有关所有选项的扩展信息,请参阅https://mongoosejs.com/docs/guide.html#options