0

I am trying to generate an auto Serial Number for my "ticketno". When a user created a new application ticket no will automatically increase by one. Can anyone tell me how can I do this?

Here is the Database Schema:

const mongoose = require('mongoose');

let kamFormSchema = new mongoose.Schema(
    {
        ticketno: { type: String, required: true },
        kcpname: { type: String, required: true },
        kcpcontact: { type: String, required: true },
        kcpnid: { type: String, required: true },
        companyname: { type: String, required: true },
        ccategory: { type: String, required: true },
        corporatecode: { type: String, required: true },
        ccategorytype: { type: String, required: true },
        ccategorysubtype: { type: String, required: true },
        totalemp: { type: String, required: true },
        msisdn: { type: String, required: true },
        approvecategory: { type: String, required: true },
        subcategory: { type: String, required: true },
        file: { type: String },
        date: { type: Date, required: true },
    },
    { collation: { locale: 'en' } }
);

//var KamForm = mongoose.model('kamForm', kamFormSchema);

module.exports = mongoose.model('kamForm', kamFormSchema);
stmp_lee
  • 663
  • 2
  • 6
  • 15

1 Answers1

0
import mongoose from 'mongoose'
import {v4} from 'uuid';
await mongoose.connect("<YOUR MONGODB ADDRESS>")

const schema = new mongoose.Schema({
    serial: {
        type: String,
        default: v4
    }
})

const model = mongoose.model("test", schema)

await new model().save()

Image sorry i don`t have 10 rang

camille
  • 16,432
  • 18
  • 38
  • 60