0

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

1 Answer 1

2

Is this what you are looking for?

Schema.find({}).populate('usergroups.usergroup').exec(...);
Sign up to request clarification or add additional context in comments.

1 Comment

Genius! I feel quite dumb now... Shows that a good night sleep can help. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.