Aggregation with $lte and $gte not working

Hello, I’m trying to run a range query ($gte) and ($lte) using the aggregation of Parse-sdk-php and it’s returning me empty

Use case

I have a collection of referrers that have the createdAt key, when searching using the parse greaterThanOrEqualTo() and lessThanOrEqualTo() methods, it is returning results, however when querying using the aggregation, it returns an empty array.

Pipeline

$query = new ParseQuery('referrers');

// $dateStart is an DateTime object
// $dateEnd is an DateTime  objectThis text will be hidden

$pipeline = [
    'match' => [
     'referrer' => ['$exists' => true],
     'createdAt' => [
         '$gte' => ParseClient::_encode($dateEnd, true),
         '$lte' => ParseClient::_encode($dateStart, true)
    ]				
];

$query->aggregate($pipeline);

Query String with decode url

  • Parse with methods greaterThanOrEqualTo() and lessThanOrEqualTo()
    {
       "referrer": {$exists: true}, 
       "createdAt":{
          "$gte": {__type: "Date", iso: "2020-01-01T17:15:40.000Z"},
          "$lte": {__type: "Date", iso: "2020-12-31T17:15:40.000Z"}
       }
    }
  • Parse with the aggregation
    {
        "referrer": {$exists: true}, 
        "createdAt":{
            "$gte": {__type: "Date", iso: "2020-01-01T17:15:40.000Z"},
            "$lte": {__type: "Date", iso: "2020-12-31T17:15:40.000Z"}
        }
    }

Settings

    OS: WIN 10 20.04

    php -v:
    PHP 7.4.9

    parse php sdk version:
    "parse/php-sdk" : "1.6.*",

Can you please have a try with _created_at?

yep, it is not working

'match' => [
       'referrer' => [
              '$exists' => true
       ],
       '_created_at' => [
               '$lte' => ParseClient::_encode($dateEnd, true),
               '$gte' => ParseClient::_encode($dateStart, true)
       ] 
]

What about the following?

'match' => [
       'referrer' => [
              '$exists' => true
       ],
       '_created_at.iso' => [
               '$lte' => "2020-12-31T17:15:40.000Z",
               '$gte' => "2020-01-01T17:15:40.000Z"
       ] 
]

I’ll post a print of the pipeline, just to make sure I’m not forgetting anything, but I haven’t been successful yet.

print with date fixed [01] and with ParseClient::_encode() [02]

the empty array would be the dump of the returned $result from

    $result = $query->aggregate($pipeline);
    var_dump($result);  // Empty Array

I tested here and the following code works for me:

'match' => [
       'referrer' => [
              '$exists' => true
       ],
       'createdAt' => [
               '$lte' => ParseClient::_encode($dateEnd, true)['iso'],
               '$gte' => ParseClient::_encode($dateStart, true)['iso']
       ] 
]
1 Like