Retrieving list of documents from collection by id in nested list

Solution 1:

Solution 1

Use ElemMatch instead of AnyIn.

var filter = Builders<Example>.Filter.ElemMatch(
    x => x.Family,
    y => y.Countries.Any(z => z.uid == porduitId));

Output


Solution 2

If you are unconfident with MongoDB .Net Driver syntax, you can convert the query as BsonDocument via MongoDB Compass (Export to language feature).

var filter = new BsonDocument("Family.Countries.uid", porduitId);