I've the following Aggregation:
$pipeline = array(
array('$match' => array(
'matchDate' => array(
'$lte' => $dateEnd, // DateTime object
'$gte' => $dateStart // DateTime object
)
)),
array('$group' => array(
'_id' => '$sport',
'count' => array('$sum' => 1)
))
);
$m = new \MongoClient('localhost');
$c = $m->selectDB('test_database')->selectCollection('Match');
$t = $c->aggregate($pipeline);
This aggregation will return an empty Result.
If I run the aggregation on my MongoDB directly, it works without problems and gives the expected results. Here is the native query.
db.Match.runCommand({
"aggregate": "Match",
"pipeline": [
{
"$match": {
"matchDate": {
"$lte": new ISODate("2015-10-07T23:59:59+02:00"),
"$gte": new ISODate("2015-10-06T00:00:00+02:00")
}
}
},
{
"$group": { "_id": "$sport", "count": { "$sum": 1 } }
}
]});
The problem occurs only with aggregation. Find queries with date ($lte, $gte) works also without problems.
Here is an example document.
{
"_id": ObjectId("5613bbb79042ad801f0041ab"),
"sport": ObjectId("5613bbb79042ad801f0041a8"),
"matchDate": new Date("2015-09-26T13:45:00+0200")
}
Has someone an idea whats happen here?
I'm Using
MongoDB Support 1.6.11
PHP 5.6.13
MongoDB 3.0.6