The first thing is that you had foreignField:questionID rather than foreignField:questionId which was producing an empty usersAnswered.
The $lookup is smart enough to it over arrays so the next stage is simply
$lookup: {
from: "profiles",
localField: "usersAnswered.userID",
foreignField: "_id",
as: "profiles",
}
This will not be in the exact format you want as the profile data will not be inside the usersAnswered array but will be at the root. Something like (using extra data to show features) :
{ _id: '00000',
question: '',
category: 'gaming',
usersAnswered:
[ { _id: 'xyz',
answer: 'some answer',
questionId: '00000',
userID: '11111' },
{ _id: 0,
answer: 'some answer',
questionId: '00000',
userID: '11111' },
{ _id: 1,
answer: 'some answer',
questionId: '00000',
userID: 222 } ],
profiles: [ { _id: 222, name: 'alex' }, { _id: '11111', name: 'alex' } ] }
As you can see user _id:11111 answered the question twice (may not be possible in your use-case) but it’s profile was produced only once.
To get your final result you may have a $set stage that $map usersAnswered using $filter on profiles. But personally, I prefer to do this kind of data cosmetic in the application layer to offload as much as possible the data access layer.