0

I want to validate an object in mongoose schema, i.e here is my schema -

logs = new Schema({
    user_id: String,
    reminder_cat: String,
    activityNote: String,
    sent_email: Number,
    added_date: Date
})

I want to validate if reminder_cat === "Renewal" then sent_email should not be more than 2 how do I achieve this at schema level. I understand there are validate function at attribute level which can be custom or provided from mongoose. But that doesn't contain the whole object so validating a dependent field is not possible. Any help or pointer will be appreciated.

Jeet
  • 5,569
  • 8
  • 43
  • 75

0 Answers0