小编Fal*_*ort的帖子

NestJS MongoDB 嵌套对象模式

我目前正在运行代码:

export class SystemInformationContent {
  createdAt: number;

  createdBy: User | mongoose.Schema.Types.ObjectId | null;

  updatedAt?: number;

  updatedBy?: User | mongoose.Schema.Types.ObjectId | null;
}

@Schema()
export class SystemInformation {
  @Prop(
    raw({
      createdAt: { type: Number, required: true },
      createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
      updatedAt: { type: Number, default: 0 },
      updatedBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        default: null,
      },
    }),
  )
  system: SystemInformationContent;
}
Run Code Online (Sandbox Code Playgroud)

我没有找到任何“扩展”模式的方法SystemInformationContent,因此raw()在装饰器中使用了该函数@Prop(),但我想知道是否有办法做这样的事情:

export class SystemInformationContent {
  @Prop({ required: true })
  createdAt: …
Run Code Online (Sandbox Code Playgroud)

mongoose nestjs typegoose

3
推荐指数
1
解决办法
6744
查看次数

标签 统计

mongoose ×1

nestjs ×1

typegoose ×1