Mongodb日期范围提取数据不在聚合中

时间:2017-09-23 06:17:12

标签: php mongodb

以下是我在mongodb中的示例文档之一

{
"_id" : ObjectId("59c5fcedc817c3da1b8b456a"),
"zoneid" : "20",
"accountid" : "34",
"sitename" : "aaa",
"requestid" : "2efa1052-7255-41cd-9d39-8628dac5ed3e",
"winbid" : NumberLong("1"),
"bidder" : "innity",
"cpm" : NumberLong("1"),
"responsetime" : NumberLong("207"),
"slotid" : "20x300x250x34x9206",
"viewerid" : "_87cd184234b181d1c601144adc0c3621",
"uniquecount" : NumberLong("0"),
"datetime" : "2017-09-23 06:19:25"
}

以下是我在php中获取mongodb数据的代码,

$ops = array(
    array(
        '$group' => array(
            "_id" => array(
                "slotid" => '$slotid',
                "bidder" => '$bidder',
                "viewerid" => '$viewerid',
                "datetime" => '$datetime'
            ) ,
            "total" => array(
                '$sum' => 1
            ) ,
            "sitename" => array(
                '$addToSet' => '$sitename'
            ) ,
            "aid" => array(
                '$addToSet' => '$accountid'
            ) 
        ) 
    ) ,
    array(
        '$match' => array(
            "datetime" => array(
                '$gt' => '2017-09-23 06:00:00'
            )
        )
    )
);
$reqbids = $db->requestbids->aggregate($ops);

它返回空结果但是如果我删除了' $ group'数组或' $ match'数组表示结果将显示,但两者都将显示空的结果显示,如下所示查询其显示的结果

    $ops = array(
    array(
        '$group' => array(
            "_id" => array(
                "slotid" => '$slotid',
                "bidder" => '$bidder',
                "viewerid" => '$viewerid',
                "datetime" => '$datetime'
            ) ,
            "total" => array(
                '$sum' => 1
            ) ,
            "sitename" => array(
                '$addToSet' => '$sitename'
            ) ,
            "aid" => array(
                '$addToSet' => '$accountid'
            ) 
        ) 
    )
);
$reqbids = $db->requestbids->aggregate($ops);

在上面的查询中,我删除了' $ match'数组,然后显示结果。在代码中出现问题,任何人都有助于解决我的问题,任何帮助表示赞赏......

0 个答案:

没有答案