I setup npm package "mongoose-sequence": "^6.0.1" and for invoiceDetail schema id field I setup invoiceDetailSchema.plugin(AutoIncrement(mongoose), { id: "invoice_detail_seq", inc_field: "id", reference_fields: ["yearId"], });
But I need insert 440 rows so I used insertMany() but sequence will not work for bulk insert. So I read max value from table and for each rows I used max++. Now I created counter.model.js and tried to updated Counter.updateOne({id : "invoice_detail_seq", reference_field : "xxx"},{}$set :{seq : max})
but this failed as per documentation it is reference_fields but in document it shows reference_values.
But bulk insert is my day to end job that I need to do. It's basically a batch open it generate few rows and insert many() that is in avoidable.
Anyone knows how to update sequence programmatically.