Can I perform mongoose update from post save middleware?
Just make the autoincrementing field virtual and you don't have to worry about post save hook...
const QuoteSchema = new Schema( { quoteNumber: { type: Number }, quoteString: { type: String }, },);QuoteSchema.virtual('quote').set(function(value) { this.quoteNumber = Number(value); this.quoteString = String(value);});QuoteSchema.virtual('quote').get(function() { return this.quoteNumber;});
Setup:
QuoteSchema.plugin(autoIncrement.plugin, { model: 'Quote', field: 'quote' });