I am writing a code in which I want my _id to be started from 1 and should be incremented. And it has to be the reference to other collections as well. Now how can I change my objectId to a number and how to let the mongo db know that it is a primary key? How to implement a custom object ID which starts from 1 and increments as well in MongoDB using mongoose?
autoIncrement.initialize(mongoose);
var districtSchema=new Schema({
_id : {type: Schema.Types.Number, unique: true},
district_name : {type: String, unique: true},
cities : [{type: Schema.Types.Number, ref:'City'}]
},
{timestamps:{createdAt:'created_at',updatedAt:'updated_at'}});
districtSchema.plugin(autoIncrement.plugin, {model:'District',field:'_id',startAt:100,incrementBy:1});
var District=mongoose.model('District',districtSchema);