I am using NestJS to write some backend code and fetch objects from MongoDB. The examples they offer in their documentation create a class annotated with @Schema()
and then concatenate it with their built-in mongoose Document
class.
@Schema()
export class Cat {
@Prop()
name: string;
}
export type CatDocument = Cat & Document;
export const CatSchema = SchemaFactory.createForClass(Cat);
I have seen other examples where the class simply extends Document
, which seems more robust and simple.
export class Cat extends Document {
@Prop()
name: string;
}
Is there a difference between the two?