@@ -37,8 +37,10 @@ Let's define the `CatSchema`:
37
37
import { Prop , Schema , SchemaFactory } from ' @nestjs/mongoose' ;
38
38
import { Document } from ' mongoose' ;
39
39
40
+ export type CatDocument = Cat & Document ;
41
+
40
42
@Schema ()
41
- export class Cat extends Document {
43
+ export class Cat {
42
44
@Prop ()
43
45
name: string ;
44
46
@@ -119,12 +121,12 @@ Once you've registered the schema, you can inject a `Cat` model into the `CatsSe
119
121
import { Model } from ' mongoose' ;
120
122
import { Injectable } from ' @nestjs/common' ;
121
123
import { InjectModel } from ' @nestjs/mongoose' ;
122
- import { Cat } from ' ./schemas/cat.schema' ;
124
+ import { Cat , CatDocument } from ' ./schemas/cat.schema' ;
123
125
import { CreateCatDto } from ' ./dto/create-cat.dto' ;
124
126
125
127
@Injectable ()
126
128
export class CatsService {
127
- constructor (@InjectModel (Cat .name ) private catModel : Model <Cat >) {}
129
+ constructor (@InjectModel (Cat .name ) private catModel : Model <CatDocument >) {}
128
130
129
131
async create(createCatDto : CreateCatDto ): Promise <Cat > {
130
132
const createdCat = new this .catModel (createCatDto );
@@ -257,7 +259,7 @@ Like other [factory providers](https://docs.nestjs.com/fundamentals/custom-provi
257
259
const schema = CatsSchema ;
258
260
schema .pre (' save' , () =>
259
261
console .log (
260
- ` ${configService .get < string > (' APP_NAME' )}: Hello from pre save ` ,
262
+ ` ${configService .get (' APP_NAME' )}: Hello from pre save ` ,
261
263
),
262
264
);
263
265
return schema ;
0 commit comments