$m = new MongoClient();
$db = $m->Forensic;
$c= $db->mobile_data;
// JavaScript function to perform
$reduce = "function (obj, prev) { prev.count++; }";
//group by source (number of messages);
$d = $c->group( ["Source" => 1], ["count" => 0], $reduce);
如何根据“Source”键对结果进行排序。
Thnaks
答案 0 :(得分:0)
I would refer you to this question,看看是否有帮助。还有一个指向MongoDB文档的链接也可能对您有所帮助。 There is also a decent explanation here also
我只是在团队中涉猎并在MongoDB中排序。
我发现的一个例子是;
db.orders.aggregate([
{
$group: {
_id: "$cust_id",
count: { $sum: 1 }
}
},
{ $match: { count: { $gt: 1 } } }
])
答案 1 :(得分:0)
找到替代解决方案
$m = new MongoClient();
$db = $m->Forensic;
$c= $db->mobile_data;
// JavaScript function to perform
$reduce = "function (obj, prev) { prev.count++; }";
//group by source (number of messages);
$d = $c->group( ["Source" => 1], ["count" => 0], $reduce);
//sort record
sort($d['retval']);
将按源字段
排序