猫鼬 nestjs 中的多类型关系

时间:2021-03-11 22:16:49

标签: mongodb mongoose nestjs mongoose-schema

我有一个这样的架构:

@Schema()
export class User {
  @Prop()
  phoneNumber: string;

  @Prop({
    type: [{ type: mongoose.Schema.Types.Mixed }],
  })
  types: TypeA[] | TypeB[];
}

在TypeA中我有这个:

@Schema()
export class TypeA {
  @Prop()
  name: string;

  @Prop()
  someOtherData: string;

  @Prop({
    type: mongoose.Schema.Types.ObjectId,
    ref: USER_MODEL
  })
  account: UserDocument;
}

因此,当我使用添加的 TypeA 保存或更新用户类型时,ObjectId('...') 不会进入其中 为了让我的问题更简单,有没有办法在猫鼬中建立 MultiType 关系?

0 个答案:

没有答案