Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggregate with pointer relation match ? #4489

Closed
xedixermawan opened this issue Jan 8, 2018 · 4 comments
Closed

aggregate with pointer relation match ? #4489

xedixermawan opened this issue Jan 8, 2018 · 4 comments

Comments

@xedixermawan
Copy link

xedixermawan commented Jan 8, 2018

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

@dplewis
Copy link
Member

dplewis commented Jan 9, 2018

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

@dplewis
Copy link
Member

dplewis commented Jan 9, 2018

Closed via #4493

@xedixermawan
Copy link
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"}}

@dplewis
Copy link
Member

dplewis commented Jan 9, 2018

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants