Currently, I'm working with NestJS to develop backend code and retrieve objects from MongoDB. In their guide, they showcase examples that involve creating a class with the @Schema()
annotation and then combining it with their pre-built mongoose Document
class.
@Schema()
export class Cat {
@Prop()
name: string;
}
export type CatDocument = Cat & Document;
export const CatSchema = SchemaFactory.createForClass(Cat);
However, I've come across other instances where the class simply extends Document
, which appears to be a more solid and straightforward approach.
export class Cat extends Document {
@Prop()
name: string;
}
Can anyone clarify the difference between these two methods?