These are chat archives for Automattic/mongoose

Sep 2017
Branden Schrenk
Sep 08 2017 15:31

I am trying to use the .pre('save' for my schema to check for a required field.

My issue is that it always works the second time I send in data after restarting my server. But the first time it never hits the pre save function after I start my node server. Any thoughts?

OrderSchema.pre('save', function (next) {
  if(this.vendor == "test"){
         OrderSchema.path('orderId').required(true, 'orderId Is Required');