我使用C#驱动程序与MongoDB。我有一个包含子文档的集合。
public class EntityA
{
public string Name { get; set; }
public string Description { get; set; }
public List<EntityB> BItems { get; set; }
}
public class EntityB
{
public string BName { get; set; }
public string BDesc { get; set; }
}
我想创建一个查询并获取 EntityB
项目的列表。
from a in mycollection
where BItems.Any(k => k.BName == entity.Name)
select a.BItems;
我可以查询嵌套的文档,但当我检索列表时,所有其他子项都会出现在列表中,我如何获取BItems的列表以满足我的条件。我可以查询子文档,但当我想获取列表时,所有Bitems都会出现在我的列表中。