Conditional Sub-document/nested parent/child schema validation

Hello, I’m working through “The Complete Node.js Course”. I’m looking for a way to validate using mongoose and joi,

I have a schema as defined below (simple defenition)

const packSchema = new mongoose.Schema({
packDetail: {
packReference: {
type: String,
},
comments: {
type: String,
},
isCertificateA {type: boolean}
},
certificateA: [certificateASchema],
});

… where certificateA is dependant on “isCertificateA” = true. I.E I only need to include it if there is call to do so. I have other certificates (B,C,D etc). I’m trying to refactor my code as well, so all Joi validation is in separate file as well as mongoose validation in separate file. Are the any tutorials or help available to figure how to do this? I almost need an if…else statement to either include a sub document or exclude it along with its validation…