Search code examples
parse-platform

Aggregation with $gte and $lte in Parse-platform with parse-sdk-php not working


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.*",


Solution

  • The following code should work:

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