【发布时间】:2016-02-22 18:05:08
【问题描述】:
我有如下文件:
{
"from":"abc@sss.ddd",
"to" :"ssd@dff.dff",
"email": "Hi hello"
}
我们如何计算“from and to”或“to and from”的总和计数? 喜欢两个人之间的交流吗?
我能够计算一种方式的总和。我想双向求和。
db.test.aggregate([
{ $group: {
"_id":{ "from": "$from", "to":"$to"},
"count":{$sum:1}
}
},
{
"$sort" :{"count":-1}
}
])
【问题讨论】:
-
我想你已经算过双向总和了。结果可能如下所示:{_id: {from: "a", to: "b"}, count 100} {_id: {from: "b", to: "a"}, count: 1000},双向结果在输出中。
-
@zydcom:不,它没有。
标签: mongodb mongodb-query aggregation-framework