MongoDB无法获得总数。
MYSQL:
select sum(play) as toplam from videos
MongoDB:
$group = $naytu->db->videos->group(array(), array("toplam" => 0), "function(obj, prev) {prev.toplam = prev.toplam + obj.play - 0;}");
结果(print_r)
Array
(
[retval] => Array
(
[0] => Array
(
[toplam] => NAN
)
)
[count] => 78656
[keys] => 1
[ok] => 1
)
问题出在哪里 ?
最佳答案
在PHP @Neils中,答案是:
$mongo->videos->aggregate([
['$group' => ['_id' => null, 'toplam' => ['$sum' => '$play']]]
]);
关于php - PHP mongodb总和查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21964001/