Convert MongoDB console aggregate to php with array -
i failing convert following mongodb console command:
db.customers.aggregate( [ { $group : { _id: { year : { $year: "$since" }, month : { $month: "$since" } }, count: { $sum: 1 } } }] );
which works php
$customers->aggregate(array( '$group' => array( '_id' => array( 'year' => array('$year' => '$since'), 'month' => array('$month' => '$since') ) ), array( 'count' => array( '$sum' => 1 ) ), ) );
which returns exception: pipeline stage specification object must contain 1 field.
tried '"$since"'
no luck
the count
field must part of group
.
$customers->aggregate(array( '$group' => array( '_id' => array( 'year' => array('$year' => '$since'), 'month' => array('$month' => '$since') ), 'count' => array( '$sum' => 1 ) ) ));
Comments
Post a Comment