Hey guys I'm trying to build a User Schema that has a role object like this and an appointment object
new mongoose.Schema({
role: {
type: String,
enum: ["admin", "partner", "basic"],
default: "basic",
},
apponitments: {
type: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Appointment",
},
],
required: function () {
return this.role === "partner";
},
}
})
my problem with this code is that no matter what the role is the appointment object is being created anyways.
I don't want this behavior is there a way to stop it ?