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

96
Vistas
Mongodb - mongoose autoincrement custom ID JS

I'm working on a membership admin pannel and I'm required to do a custom membership ID asides from the _id itself.

My schema is actually looking like this:

const mongoose = require("mongoose");

const memberSchema = mongoose.Schema(
  {
    membershipId: {
      /* AutoIncrement custom id */
      type: Number,
      default: 1,
      unique: true,
      index: true,
      autoIncrement: true,
    },
    firstName: {
      type: String,
      required: true,
    },
    lastName: {
      type: String,
      required: true,
    },
  },
  {
    timestamps: true,
  }
);

const Member = mongoose.model("Member", memberSchema);
module.exports = Member;

the point is that I would like to have something standarized by the company, such as... EMP-00001, EMP-000002, that autoincrements.

Is it possible? If so, how can I achieve this?

Thank you in advance.

about 4 years ago · Santiago Trujillo
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