Issue with mongoose-auto-increment plugin in nested models

I am trying to increment the value of procedureid & doctorId whenever the api call is being fired. I am using the below syntax. However, it's giving an error Treatment.procedureid_1 dup key when the second time I call the api through browser. i could see that values of procedureid and doctorId are increasing in identityCounter collection created by auto increment.However same is not reflected in respective schema

Can you please help me to resolve the issue.

 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);

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.