buunguyen / mongoose-deep-populate

Mongoose plugin to enable deep population of nested models ⛺
MIT License
469 stars 44 forks source link

Loading two references from model with deepPopulate #61

Closed colinscz closed 5 years ago

colinscz commented 5 years ago

Hi

I have a model which contains this attribute amongst regular ones: const dog = new mongoose.Schema({ name: {type: String, required: true}, roots: [{ _id: false, race: { type: Schema.Types.ObjectId, ref: 'Race'}, origin: { type: Schema.Types.ObjectId, ref: 'Origin'} }] });

now I want to populate both of these nested properties. I tried it like this: let dogList = await dog.find({'active': true}).deepPopulate('roots.race', 'roots.origin');

but then I always get the following error:

Mongoose: races.find({ _id: { '$in': [ ObjectId("5c102487c8381190b6183af7") ] } }, { fields: {} }) (node:40538) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '_id' of undefined (node:40538) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The table which is mentioned in the exception is correctly spelled.

Can you help me out?

colinscz commented 5 years ago

I solved the issue in the meantime, it was not related to the deepPopulate. I close the issue