AutoIncrement using mongoose

Please Guys what is the best way to implement AutoIncrement using mongoose, i tried the best two option and it wasnt working mongoose-sequence mongoose-auto-increment
const AutoIncrement = require('mongoose-sequence')(mongoose)

interface userTracks extends IUserTrack, mongoose.Document {}

const userModel = new mongoose.Schema(
{
fullName: {
type: String,
unique: false,
lowercase: true
},
email: {
type: String,
unique: true,
lowercase: true
},
phone: {
type: String
},
country: {
type: String,
unique: false,
lowercase: true
}
},
{ timestamps: true }
)

userModel.plugin(AutoIncrement, { inc_field: 'ticketNo', start_seq: 1000 })

export default mongoose.model<userTracks>('users', userModel)
const AutoIncrement = require('mongoose-sequence')(mongoose)

interface userTracks extends IUserTrack, mongoose.Document {}

const userModel = new mongoose.Schema(
{
fullName: {
type: String,
unique: false,
lowercase: true
},
email: {
type: String,
unique: true,
lowercase: true
},
phone: {
type: String
},
country: {
type: String,
unique: false,
lowercase: true
}
},
{ timestamps: true }
)

userModel.plugin(AutoIncrement, { inc_field: 'ticketNo', start_seq: 1000 })

export default mongoose.model<userTracks>('users', userModel)
2 Replies
barry
barry•2y ago
but why using mongo 😢
Exotica
Exotica•2y ago
Are you trying to use ticketNo as if it's the id? Why not just use _id auto generated by mongo? Also me have same question as barry why use mongo KEKW
Want results from more Discord servers?
Add your server