Skip to content

aggregate with pointer relation match ? #4489

Description

@xedixermawan

Hi,
is it possible to do aggregate query using match with pointer relation ?
I'm using latest branch version.
for instance request like this:

curl -X GET \
  -H "X-Parse-Application-Id: myAppId" \
  -H "X-Parse-Master-Key: myAppKey" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'match={"user":{"$eq":{"__type":"Pointer","className":"_User","objectId":"NE962BXR9x"}}}' \
	--data-urlencode 'group={"objectId":null,"total":{"$sum":"$value"}}' \
  http://localhost:1337/parse/aggregate/Distance

the Distance collection have a field calls 'user' ( a pointer type which point to collection _User.)

the aggregate above resulting empty data {"results":[]}, meanwhile it should not

Activity

  1. dplewis commented on Jan 9, 2018

    @dplewis
    Member

    A quick workaround is appending _p_ to the field name (Mongo)

    const pipeline = [
        { group: { objectId: '$_p_pointerFieldName' } }
    ];
    

    Edit: Postgres Supports { group: { objectId: '$pointerFieldName' } } works out of the box

  2. dplewis commented on Jan 9, 2018

    @dplewis
    Member

    Closed via #4493

  3. xedixermawan commented on Jan 9, 2018

    @xedixermawan
    Author

    Hi @dplewis , thanks for quick reply & implementation.
    I tried your code change and it's work by appending _p_.
    the thing I notice, the form of aggregate query is not consistent with the form of relational query ( a query using keyword where ).
    for my query above , here is the change I made to make it work.

    match={"_p_user":"_User$m7WeWjAQ3P"}
    group={"objectId":"$_p_user","total":{"$sum":"$value"}}
    
  4. dplewis commented on Jan 9, 2018

    @dplewis
    Member

    @xedixermawan In mongo especially there are multiple stages (20+) for aggregates so adding transforms for all of them would take some time. I guess we can transform the main 3 group, match, project. You want to open a PR to add pointer transform to match? I'll review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions