【发布时间】:2014-03-18 18:06:31
【问题描述】:
我有一个 Mongo Doc 如下
{
userid: "jd",
fullname: "john doe",
Tracker : [
{
type: "aaa",
total: "111"
state: "Active"
}
{
type: "bbb",
total: "222"
state: "Active"
}
{
type: "aaa",
total: "333"
state: "Active"
}
{
type: "ccc",
total: "111"
state: "Active"
}
{
type: "ccc",
total: "111"
state: "Inactive"
}
]
}
我的目标是在 vb.net(或我可以转换为 vb.net 的 c#)中有一个 linq 查询,它总结了每种类型的所有总数,但在列中,而不是在行中
userid fullname aaa bbb ccc
jd john doe 444 222 111
到目前为止,我得到了: 注意:_users 是我的 mongocollection
dim results = From u in _users.AsQueryable(Of MyClass)() _
Order by _u.fullname
Where _u.Tracker.Any(Function(typestate) typestate.state="Active"
Select _u.userid, _u.fullname, totalAAA = _u.Tracker.Sum(Function(tAAA) tAAA.total), totalBBB = _u.Tracker.Sum(Function(tBBB) tBBB.total), totalCCC = _u.Tracker.Sum(Function(tCCC) tCCC.total)
我知道totalAAA、totalBBB 和totalCCC 会产生相同的结果,我需要为它们中的每一个设置一个特定的were 子句,只是不知道该怎么做,或者是否有更好的方法
谢谢
【问题讨论】:
标签: .net vb.net mongodb linq aggregation-framework