我正在将我的应用程序从 express.js 移动到 Nest.js,并且我找不到一种方法来引用另一个 mongoose Schema,而不使用使用 mongoose.Schema({...}) 声明 Schema 的旧方法。
让我们使用文档中的示例,以便我可以澄清我的问题:
@Schema()
export class Cat extends Document {
@Prop()
name: string;
}
export const CatSchema = SchemaFactory.createForClass(Cat);
Run Code Online (Sandbox Code Playgroud)
现在,我想要的是这样的:
@Schema()
export class Owner extends Document {
@Prop({type: [Cat], required: true})
cats: Cat[];
}
export const OwnerSchema = SchemaFactory.createForClass(Owner);
Run Code Online (Sandbox Code Playgroud)
当我以这种方式定义模式时,我会收到一个错误,类似于:无效的模式配置:Cat
不是数组中的有效类型cats
那么,使用这种更面向对象的方法来定义架构,在另一个架构中引用一个架构的正确方法是什么?