In the current version of Mongoose, I still donβt see that multi ref is possible with the syntax as you want. But you can use part of the "Population through Databases" method described here . We just need to move the demographic logic into an explicit version of the population method:
var PeopleSchema = new Schema({ peopleType:{ //Just ObjectId here, without ref type: mongoose.Schema.Types.ObjectId, required: true, }, modelNameOfThePeopleType:{ type: mongoose.Schema.Types.String, required: true } }) //And after that var People = mongoose.model('People', PeopleSchema); People.findById(_id) .then(function(person) { return person.populate({ path: 'peopleType', model: person.modelNameOfThePeopleType }); }) .then(populatedPerson) { //Here peopleType populated } ...
source share