nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.76k stars 7.64k forks source link

Should my schemas extend mongoose Document? #5697

Closed Pacheco95 closed 4 years ago

Pacheco95 commented 4 years ago

In the documentation

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type CatDocument = Cat & Document;

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

  @Prop()
  age: number;

  @Prop()
  breed: string;
}

export const CatSchema = SchemaFactory.createForClass(Cat);

the model (CatDocument) is declared and exported as a separated type from schema (CatSchema), but in the example it is extending mongoose Document. What approach should I use? Is there any difference?

https://github.com/nestjs/nest/blob/1b9341411707a545288421453cd899fbc5029e78/sample/06-mongoose/src/cats/schemas/cat.schema.ts#L5

kamilmysliwiec commented 4 years ago

The example was invalid, thanks for pointing that out! I've just pushed a commit with a fix.