小编Jer*_*Lee的帖子

将 NestJs + Typegoose 中的 _id 替换为 id

我使用 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;
}
Run Code Online (Sandbox Code Playgroud)
@Injectable()
export class UsersService {
  constructor(
    @InjectModel(UserEntity) private readonly userModel: ModelType<UserEntity>,
  ) {}

  getOneByEmail(email: string) {
    return from(
      this.userModel
        .findOne({ email }) …
Run Code Online (Sandbox Code Playgroud)

nestjs typegoose

8
推荐指数
1
解决办法
6636
查看次数

标签 统计

nestjs ×1

typegoose ×1