Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda