title: How do I prevent unwanted object properties from the client in nestjs while updating an existing row in mongodb
body: <p>Creating a new user will ignore non-specified objects from <code>create-user.dto.ts</code></p>
  
  <p>However when I update the user it will add unwanted fields like this:</p>
  
  <pre><code>// 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[];
  }
  </code></pre>
  
  <p>This is the update action from the user service</p>
  
  <pre><code>// 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);
      }
    }
  </code></pre>
  
  <p>And here is the user.controller.ts</p>
  
  <pre><code>  @Patch()
    @UsePipes(CustomValidationPipe)
    async update(@Body() data: UpdateUserDto) {
      return this.userService.update(data);
    }
  </code></pre>
  
  <p>The client patch data:</p>
  
  <pre><code>// Unwanted junk from client
  {
    "email": "newemail@gmail.com",
    "junk": "junk"
  }
  </code></pre>
  
  <p>The <code>email</code> will update properly but the row will have a new unwanted property <code>junk</code> with the value <code>junk</code></p>