我正在使用aggregate
以下代码:
$result = \DB::connection('mongodb')->collection('urls')->raw(function($collection) use ($alias)
{
$from = new \MongoDate( strtotime('2015-01-01 00:00:00') );
$to = new \MongoDate( strtotime('2015-01-31 00:00:00') );
return $collection->aggregate([
['$match' =>
[
'alias' => $alias,
'clicks.created_at' => [
'$lte' => $to,
'$gte' => $from
]
]
],
['$unwind' => '$clicks'],
['$project' => [
'clicks' => 1
]
],
['$group' => [
'_id' => [ 'day' => [ '$dateToString' => [ 'format' => '%Y-%m-%d', 'date' => '$clicks.created_at' ] ] ],
'count' => [ '$sum' => 1 ]
]
],
]);
});
return $result;
虽然我在这个时间跨度内有记录,但没有记录返回。知道为什么吗?