【发布时间】:2021-09-08 20:03:39
【问题描述】:
我在后端使用nestJs,并且我有一个以数组作为属性的模式。出于某种目的,我需要每个数组属性的对象 id,但没有生成 id。
数组内对象的 DTO:
export class EmergencyContact {
@Prop({ _id: true })
_id: string;
@Prop()
@ApiProperty()
@IsNotEmpty()
title: string;
@Prop()
@ApiProperty()
@IsNotEmpty()
contactNumber: string;
@Prop()
status: boolean;
}
架构 DTO:
@Schema({ timestamps: true })
export class EDiary {
_id: string;
@Prop()
@ApiProperty()
@IsNotEmpty()
state: string;
@ApiProperty()
@Prop()
@Type(() => EmergencyContact)
emergencyContact: EmergencyContact[];
}
【问题讨论】: