I use NestJs + Typegoose. How to replace _id to id in NestJs + Typegoose? I didn't find a clear example. I've tried something but without any results.
@modelOptions({
schemaOptions: {
collection: 'users',
},
})
export class UserEntity {
@prop()
id?: string;
@prop({ required: true })
public email: string;
@prop({ required: true })
public password: string;
@prop({ enum: UserRole, default: UserRole.User, type: String })
public role: UserRole;
@prop({ default: null })
public subscription: string;
}
@Injectable()
export class UsersService {
constructor(
@InjectModel(UserEntity) private readonly userModel: ModelType<UserEntity>,
) {}
getOneByEmail(email: string) {
return from(
this.userModel
.findOne({ email })
.select('-password')
.lean(),
);
}
}