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

97
Views
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
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!