Supposing you need parent reference of Task schema, and parent can be either manager or developer. You don’t have to define both reference IDs in Task schema. Instead MongoDB provides feature to define arbitrary reference.
const taskSchema = new Schema({
...
parent: [{
_id: {
type: String,
refPath: 'parent.object'
},
object: String
}],
});
You can assign value as Manager schema ID or Developer schema ID.
