You can create Dynamic Reference with refPath
. In that case you would need to create one additional property that would store the actual reference. When populating, Mongoose will check the value in that new field. You can do it like this:
const documentSchema = Schema({
_id: Schema.Types.ObjectId,
title: String,
date: Date,
references: { type: [Schema.Types.ObjectId], refPath: 'model_type' },
model_type: { type: String, enum: ['Student', 'Professor', 'Administrator' ], required: true }
});