I have a collection which describes requests. It looks like this:
const requestSchema = mongoose.Schema({
status: {
type: String,
required: true,
enum: ["available", "failed", "succeed"],
},
errorCode: { type: String , required : (when status is failed)},
});
My goal is to require errorCode only if status is set to 'failed' and don't allow it to exist otherwise. And if possible to have it removed when status is changed to 'succeed' for example. I can't quite find an answer anywhere.