我正在尝试增加procedureid
&的价值。每当api呼叫被解雇时doctorId
。我使用以下语法。但是,当我第二次通过浏览器调用api时,它会给出错误Treatment.procedureid_1 dup key
。
我可以看到在自动增量创建的identityCounter集合中,procedureid和doctorId的值正在增加。但是相应的架构中没有反映出来
你能帮我解决一下这个问题。
var mongoose = require('mongoose');
var autoIncrement = require('mongoose-auto-increment');
var hospitalDoctorSchema = new Schema({
Treatment: {
procedureid: { type: Number,required: true, unique: true,default: 0 },
doctor: {
doctorId: { type: Number, required: true, unique: true, dropDups: true, default: 0 },
},
},
updated_at: { type: Date, required: true, default: Date.now }
});
autoIncrement.initialize(mongoose.connection);
hospitalDoctorSchema.plugin(autoIncrement.plugin, {
model: collection,
field: 'Treatment.procedureid',
startAt: 10000,
incrementBy: 1
});
hospitalDoctorSchema.plugin(autoIncrement.plugin, {
model: collection,
field: 'Treatment.doctor.doctorId',
startAt: 10000,
incrementBy: 1
});
//create collection.
module.exports.hospitalModel = mongoose.model(collection, hospitalDoctorSchema);