Hi,
A normal find() query and projection will return matches at the document level, as you have discovered.
Assuming you are using MongoDB 2.6 or newer, the general approach would be:
- start with your $text match (this pipeline opereation can only appear once, and must be at the beginning of your aggregation query)
- $unwind the subdocument array
- $match against { username: 'John Doe' }
- (optional) $group by '_id' to recombine the subdocuments
If you'd like to provide an example document, desired result, and your specific version of MongoDB someone can help with a suggested query.
Regards,
Stephen