Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!