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.