I having issue on mongo db with codeignitor3 to getting records using group by '$group' in aggregate function on date as 'created' but we have datetime format in table USER_DATA mongoDb database. when I run the mongo query I am getting error "can't convert from BSON type string to Date"
$date = date('Y-m-d',strtotime(-1 month));
$users = $this->common_model->aggregate($this->database['USER_DATA'], array(array('$match' => array('created' => array('$gte' => $date))),
array('$sort' => array('_id.created' => -1)),
array('$group' => array('_id' => array('year' => array('$year' => '$created'), 'month' => array('$month' => '$created'), 'day' => array('$dayOfMonth' => '$created')), 'count' => array('$sum' => 1))),
));
before we are using
array('$group' => array('_id' => array('created' => '$created')), 'count' => array('$sum' => 1)),
Its was working fine but records not as required per group by date, because in DB table we have datetime format. Is their any way on mongo query with codeignitor library function aggrigation?