But this is essentially allowing the type to be “any” object. I want the type to be an ObjectId of some document; it’s just that I want to be able to reference the id’s of documents from more than one model and therefore more than one collection (Student, Professor, and Administrator in this example). If I set the type to Schema.Types.Mixed
, how will Mongo know which collection to query for the id that is stored there?
Or do you mean that instead of storing an ObjectId there, I would be storing an object that can have one of these three possible forms?
{ type: Schema.Types.ObjectId, ref: 'Student' }
{ type: Schema.Types.ObjectId, ref: 'Professor' }
{ type: Schema.Types.ObjectId, ref: 'Administrator' }
(If that is the case, then I guess the answer to my original question would be “no, it isn’t possible to have ‘ref’ refer to more than one data model at a time”.)