MongoDB不返回结果或忽略lte / gte

时间:2015-05-12 13:58:53

标签: mongodb laravel-5

我正在使用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;

虽然我在这个时间跨度内有记录,但没有记录返回。知道为什么吗?

0 个答案:

没有答案