Reputation: 107
I have this in my model:
User.js:
...
usergroups: [{usergroup:{type: mongoose.Schema.Types.ObjectId, ref: 'UserGroup'},
status: {type: String, default: 'Pending'}}],
...
When a user joins a user group, the ID of the group gets stored in the usergroup field of the user model array, and the status field defaults to Pending, awaiting approval from an admin. I can populate an array of IDs no problem, but I am not sure how to do it when the field to populate is paired with another one.
Am I getting my model wrong or missing something obvious?
Help please!
Thank you
Upvotes: 0
Views: 1002
Reputation: 1590
Is this what you are looking for?
Schema.find({}).populate('usergroups.usergroup').exec(...);
Upvotes: 2