You can set the 'default' option to a function that tests for some condition. The return value of the function is then set as the default value when the object is first created. This is how it would look like.
image: {
type: ObjectId,
default: function() {
if (this.gender === "male") {
return male placeholder image;
} else {
return female placeholder image;
}
}
}
For the specific purpose of setting up a default placeholder image, I think using a link as the default value is a much simpler approach. This is how the schema would look like.
image: {
type: String,
default: function() {
if (this.gender === "male") {
return "male placeholder link";
} else {
return "female placeholder link";
}
}
}
These are links to the placeholder images if someone might need them.
https://i.ibb.co/gSbgf9K/male-placeholder.jpg
https://i.ibb.co/dKx0vDS/woman-placeholder.jpg