日期比较返回错误的结果

时间:2018-01-09 20:51:56

标签: php mongodb mongodb-query

我试图返回属于特定范围的记录,但似乎返回了错误的记录,当我选择单独使用$lt条件时,不会发生此问题。

以下是返回的json

{
"_id": {
    "$oid": "5a5528c471872a00ee77731d"
},
"histories": [
    {
        "created": "2017-09-21T08:24:18.716+0100",
        "items": [
            {
                "field": "status",
                "fieldtype": "jira",
                "fieldId": "status",
                "from": "10007",
                "fromString": "With Testing",
                "to": "10012",
                "toString": "Completed"
            }
        ]
    },
    {
        "created": "2017-10-27T15:10:58.179+0100",
        "items": [
            {
                "field": "status",
                "fieldtype": "jira",
                "fieldId": "status",
                "from": "10007",
                "fromString": "With Testing",
                "to": "10012",
                "toString": "Completed"
            }
        ]
    }
]
}

以下是与注释掉的尝试一起使用的聚合管道。

'pipeline' => [
[
    '$match' => [
        'histories.created' => [
            '$gte' => '2017-09-28T00:00:00Z+0100',
            '$lt' => '2017-10-04T00:00:00Z+0100' 
            //'$gte' => '2017-09-28T00:00:00Z',
            //'$lt' => '2017-10-04T00:00:00Z' 
            //'$gte' => '2017-09-28',
            //'$lt' => '2017-10-04' 
        ]
    ]
]
]

我查询的mongo集合没有histories.created,其值介于2017-09-28 to 2017-10-04之间,所以我应该从上面的查询中取出一个空的json而不是一条记录

{}

我不确定我做错了什么,我尝试将日期字符串转换为UTCDateTime个对象,但我仍然得到相同的结果

我正在使用mongodb和php

0 个答案:

没有答案