クエリを実行した後
$orders = Orders::connection()->connection->command(array(
'aggregate' => 'orders',
'pipeline' => array(
array(
'$group' => array(
'_id' => array('cust_id'=>'$cust_id','ord_date'=>'$ord_date'),
'total' => array( '$sum' => '$price') ,
),
),
)
));
$ordersの出力配列を次のように取得します
Array
(
[0] => Array
(
[_id] => Array
(
[cust_id] => xyz123
[ord_date] => MongoDate Object
(
[sec] => 1351875851
[usec] => 102000
)
)
[total] => 75
)
[1] => Array
(
[_id] => Array
(
[cust_id] => abc123
[ord_date] => MongoDate Object
(
[sec] => 1351875851
[usec] => 102000
)
)
[total] => 125
)
)
正しく印刷するために、MongoDateオブジェクトで次のことを試しました
foreach($orders['result'] as $o){
$date = $o['ord_date'];
echo date('Y-M-d',$date->sec);
}
また試した
foreach($orders['result'] as $o){
$date = new MongoDate ($o['ord_date']);
echo date('Y-M-d',$date->sec);
}
誰かが私にそうするための正しい方法を教えてもらえますか?