Hello, can you show me your model ? I have the mongoose Schema and one class model for validation. (class-validator). But they dont extends form thype Document. Can i exend from the Document class on the validation model without any problems ?
you can extend the Document type by creating an intersection type like this export type UserDocument = User & Document;and then pass the UserDocument type when you inject in your service. This is assuming you're using the InjectModel decorator that from the nestjs/mongose module. An example of what you would pass into your user service constructor would look like this @InjectModel(User.name) private readonly userModel: Model<UserDocument>
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello, can you show me your model ? I have the mongoose Schema and one class model for validation. (class-validator). But they dont extends form thype Document. Can i exend from the Document class on the validation model without any problems ?
best regards, alessandro
you can extend the Document type by creating an intersection type like this
export type UserDocument = User & Document;
and then pass the UserDocument type when you inject in your service. This is assuming you're using the InjectModel decorator that from the nestjs/mongose module. An example of what you would pass into your user service constructor would look like this@InjectModel(User.name) private readonly userModel: Model<UserDocument>