Mongo中存放的date是string格式,如:'2014-07-09 09:00:00'
db.test.aggregate{{$project:{"date": {$substr : ["$time",0,10]}}}}
请问各位,如何将此句话转化为PHP,谢谢!
以下实现:每日收入汇总:
$this->mongo_Collelection->aggregate( array('$project' => array('date' => '$time')),//这里如何写substr array('$group' => array('_id' => array('date' => '$date'),
'sum' => array('$sum' => '$income'),
)) );
PS:如果其他地方有错误,请指出,谢谢!
time_start 和 income 是Mongo中的field,
$this->mongo_Collelection->aggregate(
//array('$match' => $where1),//where 条件 array('$project' => array( 'date' => array('$substr' => array('time_start', 0, 10)),//取前十,time_start重命名为date 'income' => 1, //income 用于下面的sum ),// project 为以下聚合做准备 array('$group' => array('_id' => array('date' => '$date'), // group by date 'sumincome' => array('$sum' => '$income'), // sum(income) as sumincome )
),
//array('$match' => $where2),//having );
unwind 什么的还不了解,暂时解决这个问题...