Answer the question
In order to leave comments, you need to log in
Mongoose: typing virtual fields?
I am learning mongodb. I am writing a nestjs + mongoose + typescript application.
I have a constant problem with typing virtual fields.
I will give an example and explain the essence.
For example, there is a user schema:
@Schema({ toJSON: { virtuals: true }, toObject: { virtuals: true } })
export class User {
@Prop({ required: true })
email: string;
@Prop({ required: true })
password: string;
}
{
_id: 61205e32ac6ca237401712ec,
email: '[email protected]',
__v: 0,
id: '61205e32ac6ca237401712ec'
}
Answer the question
In order to leave comments, you need to log in
it is possible to inherit from Document, however, in the second paragraph of the same dock page, this is not recommended
import { Document } from "mongoose";
interface User extends Document { /* */ }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question