Skip to content

Commit 1c1d18e

Browse files
Update mongo.md
1 parent 1c60d81 commit 1c1d18e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

content/techniques/mongo.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ Let's define the `CatSchema`:
3737
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
3838
import { Document } from 'mongoose';
3939

40+
export type CatDocument = Cat & Document;
41+
4042
@Schema()
41-
export class Cat extends Document {
43+
export class Cat {
4244
@Prop()
4345
name: string;
4446

@@ -119,12 +121,12 @@ Once you've registered the schema, you can inject a `Cat` model into the `CatsSe
119121
import { Model } from 'mongoose';
120122
import { Injectable } from '@nestjs/common';
121123
import { InjectModel } from '@nestjs/mongoose';
122-
import { Cat } from './schemas/cat.schema';
124+
import { Cat, CatDocument } from './schemas/cat.schema';
123125
import { CreateCatDto } from './dto/create-cat.dto';
124126

125127
@Injectable()
126128
export class CatsService {
127-
constructor(@InjectModel(Cat.name) private catModel: Model<Cat>) {}
129+
constructor(@InjectModel(Cat.name) private catModel: Model<CatDocument>) {}
128130

129131
async create(createCatDto: CreateCatDto): Promise<Cat> {
130132
const createdCat = new this.catModel(createCatDto);
@@ -257,7 +259,7 @@ Like other [factory providers](https://docs.nestjs.com/fundamentals/custom-provi
257259
const schema = CatsSchema;
258260
schema.pre('save', () =>
259261
console.log(
260-
`${configService.get<string>('APP_NAME')}: Hello from pre save`,
262+
`${configService.get('APP_NAME')}: Hello from pre save`,
261263
),
262264
);
263265
return schema;

0 commit comments

Comments
 (0)