我使用 NestJs + Typegoose。如何在 NestJs + Typegoose 中将 _id 替换为 id?我没有找到一个明确的例子。我尝试了一些东西,但没有任何结果。
@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(),
);
}
}