小编Tea*_*ulo的帖子

如何在更新 mongodb 中的现有行时防止来自 nestjs 中客户端的不需要的对象属性

创建新用户将忽略来自 create-user.dto.ts

但是,当我更新用户时,它会添加不需要的字段,如下所示:

// update-user.dto.ts
import { IsEmail } from 'class-validator';
import { Address } from '../model/address';

export class UpdateUserDto {
  firstName: string;

  lastName: string;

  @IsEmail(undefined, { message: 'Not a valid e-mail' })
  email: string;

  username: string;

  password: string;

  addresses: Address[];
}
Run Code Online (Sandbox Code Playgroud)

这是来自用户服务的更新操作

// user.service.ts
  async update(data: UpdateUserDto) {
    try {
      this.logger.log(data);
      const id = '5c6dd9852d4f441638c2df86';
      const user = await this.userRepository.update(id, data);

      return { message: 'Updated your information' };
    } catch (error) {
      this.logger.log(error);
      throw new HttpException('', HttpStatus.INTERNAL_SERVER_ERROR);
    }
  } …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js typeorm class-validator nestjs

11
推荐指数
3
解决办法
3245
查看次数

如何使用 NestJS 序列化返回 id 字符串而不是 _bsontype

使用时

@UseInterceptors(ClassSerializerInterceptor)
Run Code Online (Sandbox Code Playgroud)

就像这里的文档中所解释的那样

我得到了所需的过滤结果,但是在使用 mongodb 时,id 被格式化_bsontype而不是string像以前那样没有拦截器的正常格式,如下所示:

{
    "id": {
        "_bsontype": "ObjectID",
        "id": {
            "0": 92,
            "1": 108,
            "2": 182,
            "3": 85,
            "4": 185,
            "5": 20,
            "6": 221,
            "7": 12,
            "8": 56,
            "9": 66,
            "10": 131,
            "11": 172
        }
    },
    "createdAt": "2019-02-20T02:07:17.895Z",
    "updatedAt": "2019-02-20T02:07:17.895Z",
    "firstName": "The First Name",
    "lastName": "The Last Name",
    "email": "giberish@gmail.com"
}
Run Code Online (Sandbox Code Playgroud)

如何将其转换回像这样的普通 id 字符串?

{
    "id": "5c6cb655b914dd0c384283ac",
    "createdAt": "2019-02-20T02:07:17.895Z",
    "updatedAt": "2019-02-20T02:07:17.895Z",
    "firstName": "The First Name",
    "lastName": "The Last Name",
    "email": …
Run Code Online (Sandbox Code Playgroud)

node.js typescript typeorm nestjs class-transformer

3
推荐指数
1
解决办法
1831
查看次数

如何在 mongodb 中使用 typeorm 中的“OR”运算符

我试过使用

userRepository.find({
  where: [
    {
      email: 'giberish@gmail.com',
    },
    {
      username: 'thisismyusername',
    },
  ]
});
Run Code Online (Sandbox Code Playgroud)

就像 typeorm 文档中解释的那样,但我收到此错误:

  errmsg:
   'Error getting filter : Error getting filter BSON field from doc = [{find user} {filter [[{email giberish@gmail.com}] [{username thisismyusername}]]} {returnKey false} {showRecordId false} {$clusterTime [{clusterTime 6660127540193001473} {signature [{hash [184 253 193 112 111 39 205 239 38 92 178 205 149 85 131 136 252 114 180 30]} {keyId 6637077103550398465}]}]}] : not bson []interface {} [[{email craftball@gmail.com}] [{username thisismyusername}]]\n\tat erh/mongonet/bsonutil.go:122\n\tat 10gen/atlasproxy/bson_util.go:32\n\tat 10gen/atlasproxy/commands_security.go:521\n\tat …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js typescript typeorm nestjs

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

为什么 Chrome 中的表格处理文本溢出的方式与 Firefox 中的不同?

我在 Chrome 和 Firefox 中运行相同的 Anuglar (mat-table) html。Chrome 有一个滚动条来滚动表格单元格,而 Firefox 则重叠文本

    <td
      style="
        min-width: 160px;
        max-width: 400px;
        text-overflow: clip;
        overflow: hidden;
        overflow-x: scroll;
        white-space: nowrap;
      "
      mat-cell
      *matCellDef="let element"
    >
Run Code Online (Sandbox Code Playgroud)

铬合金: 在此输入图像描述

火狐浏览器 在此输入图像描述

css firefox google-chrome angular-material angular

0
推荐指数
1
解决办法
414
查看次数