【发布时间】:2014-07-30 23:17:50
【问题描述】:
我的应用程序使用 .net c# 驱动程序访问 mongodb。
我的数据结构是这样的:
{
"_id" : ObjectId("53d97351e37f520a342e152a"),
"Name" : "full question test 2",
"keywords" : ["personality", "extraversion", "agreeableness"],
"Questions" : [{
"type" : "likert",
"text" : "question 1",
},
{
"type" : "likert",
"text" : "question 2",
}]
}
我想要做的是从问题数组中只选择类型列。
这是我现在的 linq 代码:
from e in collection.AsQueryable<scales>()
where e.Name == "full question test 2"
select new { e.Id, e.Name, e.Questions}
这将返回所有问题属性(类型和文本)。我只想要类型。我可以通过说诸如 e.Questions[0].text,e.Questions[1].text 之类的话来做到这一点。
但问题的数量因文件而异,所以我想要一个不需要这种手动编码的解决方案。
接受想法!
【问题讨论】:
标签: c# mongodb mongodb-query aggregation-framework mongodb-.net-driver