Mongoose auto increment ID

Viewed 30

I would like to create increment id with three formats For students it will be with 5 column starts from 00000 For teachers it will be 3 starts from 000 and so on .. How do i do that I tried auto-increment npm package but it seems that it's not supported anymore

Student model:

const mongoose = require(`mongoose`);

const Schema = mongoose.Schema;

const studentSchema = new Schema({
  studentId: {
    type: Number,
  },
  name: {
    type: String,
    required: true,
  },
  password: {
    type: String,
    required: true,
  },
});

module.exports = mongoose.model("Student", studentSchema);
0 Answers
Related