MongoDB日期范围查询在php中返回空结果

时间:2019-11-24 12:55:06

标签: php mongodb

我的使用php的查询返回空结果,但是如果我在罗盘中运行相同的查询,它将返回正确的文档。这是我的php代码

我正在使用“ UTCDateTime()”转换日期,并且日期正确。
在第一次迭代$Interval =“ 2019-08-24”

这将使:

$FirstDay =“ 2019-08-01”

$LastDay =“ 2019-08-31”

示例文档在这些日期之内,但在我运行查询时未返回

foreach ($DateIntervals as $Interval) {

            Service::debug($Interval, true);

            $FirstDay = date('Y-m-01', strtotime($Interval));
            $LastDay = date('Y-m-t', strtotime($Interval));

            $FirstDay = new DateTime($FirstDay);
            $LastDay = new DateTime($LastDay);

            $FirstDay = new MongoDB\BSON\UTCDateTime($FirstDay);
            $LastDay = new MongoDB\BSON\UTCDateTime($LastDay);

            $cursor = $UnifiUniqueUsersCollection->aggregate(
                [
                    [
                        '$match' =>
                            [
                                'dDateTime' => [
                                    '$gte' => $FirstDay,
                                    '$lte' => $LastDay
                                ]
                            ]
                    ]
                ]);


            foreach ($cursor as $document) {

                dump($document);
            }
        } 

这是一个示例文档:

_id:5dd6ff1e59fae645da1ca1cf
sUserMac:"74:b5:87:85:57:09"
dDateTime:2019-08-22T15:36:42.634+00:00
sSiteID:"558d22a9e4b08308461fca5b"

我不确定自己做错了什么,感谢您的帮助!

0 个答案:

没有答案