**I have a database in MongoDB
if I use CMD using the aggrate script the results will appear**
result like this using cmd
db.getCollection('teacher').aggregate( [ {$group : {_id: '$name', count : {$sum : 1}}} ])
{ "_id" : "budi", "count" : 3 }
{ "_id" : "sinta", "count" : 3 }
如果PHP的强制执行与使用CMD导致的结果不同
这是PHP中的代码
**
$cmd = new \MongoDB\Driver\Command([
'aggregate' => 'collection',
'pipeline' => [['$group' => ['_id' => '$name', 'count' => ['$sum' => 1]]]],
'cursor' => new stdClass,
]);
$cursor = $manager->executeCommand('teacher', $cmd);
$records = iterator_to_array($cursor,true);
var_dump($records);
echo '<pre>';
echo print_r($records);
echo '</pre>';
**
从头开始
**array(0) { }
Array
(
)**
please help me to generate data like in CMD using PHP