Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
Mongoose additional schema field

I am using mongodb (mongoose) in my nest js project. I created this schema that i used for authentication:

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type AuthenticationDocument = Authentication & Document;

@Schema()
export class Authentication {
  @Prop({ required: true })
  email: string;

  @Prop({ required: true })
  password: string;

  @Prop()
  isActive: boolean;

  @Prop()
  userType: string;
}

export const AuthenticationSchema =
  SchemaFactory.createForClass(Authentication);

Everything is working.
This schema is used when user wants to register or login.
. This schema generates in mongodb something like this:

_id:eidfywieu6r88ey9ew
password:$2b$10$BdQIK/EdDC6/UMNlE/Awye48AFS8Vcpecm6lOixhl4zTLkb0EIdIW
email:test@test.com
__v:0

Question: If i want to add additional field in my monngodb for example when user does additional action. Could i add additional field in mongodb like:

_id:eidfywieu6r88ey9ew
password:$2b$10$BdQIK/EdDC6/UMNlE/Awye48AFS8Vcpecm6lOixhl4zTLkb0EIdIW
email:test@test.com
code: test code  // added field
__v:0

Or i should initiate the code field when user is registered the first time and to change the schema like

@Schema()
export class Authentication {
  @Prop({
    required: true
  })
  email: string;

  @Prop({
    required: true
  })
  password: string;

  @Prop()
  isActive: boolean;

  @Prop()
  userType: string;

  @Prop()
  code: null;
}

? Which is the best solution?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda