Parse-server: Find the distinct values for a specified column

Created on 8 Jul 2016  路  24Comments  路  Source: parse-community/parse-server

Find the distinct values for a specified column across a single table and returns the result,

Based on this discussion:
https://www.parse.com/questions/retrieving-unique-values

enhancement up for grabs

Most helpful comment

I think the API suggested in the beginning of the thread would be good:
curl -X GET \
-H "X-Parse-Application-Id: REDACTED" \
-H "X-Parse-REST-API-Key: REDACTED" \
-G \
--data-urlencode 'distinct=score' \
https://api.parse.com/1/classes/GameScore

We would have to handle this in ClassesRouter -> rest -> RestQuery -> DataBaseController -> Mongo and Postrgres adapters.

For mongo we can implement it using https://docs.mongodb.com/manual/reference/method/db.collection.distinct/.

For postgres using SELECT DISTINCT ... (https://www.postgresql.org/docs/9.0/static/sql-select.html)

I've just added it to my personal kanban. I can try to write something soon.

All 24 comments

This is not implemented yet but you could work on a PR that implements it

I can take this up. Is there a API design for this?
looking at how REST queries work I would assume it to look something like:

curl -X GET \
  -H "X-Parse-Application-Id: REDACTED" \
  -H "X-Parse-REST-API-Key: REDACTED" \
  -G \
  --data-urlencode 'distinct=score' \
  https://api.parse.com/1/classes/GameScore

We usually Mark custom operators with a $ i.e. $distinct

Any news regarding this enhancement ?

thanks.

@ranhsd It's up for the taking :)

@flovilmart This change should be done in the DataBaseController.js right ?

@ranhsd, I just poked around out of curiosity, I'd think that you'd need to add it first to RestQuery which will call find on the DataBaseController that will then use the MongoCollection.find (or postgress). Would at least need to touch a comment in LiveQuery/QueryTools.js

This is just my quick look around. Seems like following how skip and limit are done are good parallels since they are constraints on a find, like distinct is.

ymmv :)

+1 for this feature

I know MongoDB well and what would be great for me is a way to use mongo directly, with the aggregation framework and all. I know it's a lot a ask.

+1

+1 Any news on this implementation?

@pewh no, but PRs are more than welcome :wink:

Im sure there was a PR already for this! can anybody confirm?

+1 for this. @Cliffordwh - I did a quick search on open/closed PRs and couldn't find this. Hoping someone will pick this up and implement soon.

china parse

Key Operation

  • groupby
  • groupcount
  • sum
  • average
  • max
  • min
  • having
curl -X GET 
    `-H "X-Bmob-Application-Id: Your Application ID" \
    -H "X-Bmob-REST-API-Key: Your REST API Key" \
    -G \
    --data-urlencode 'groupby=score' \
    https://api.bmob.cn/1/classes/GameScore

[
    {
        "score": 78
    },
    {
        "score": 89
    }
]


curl -X GET \
    -H "X-Bmob-Application-Id: Your Application ID" \
    -H "X-Bmob-REST-API-Key: Your REST API Key" \
    -G \
    --data-urlencode 'sum=score&groupby=createdAt&groupcount=true&order=-createdAt' \
    https://api.bmob.cn/1/classes/GameScore

[
    {
        "_sumScore": 2398,
        "_count": 10,
        "createdAt": "2014-02-05"
    },
    {
        "_sumScore": 100,
        "_count": 2,
        "createdAt": "2014-01-01"
    },
]

curl -X GET \
    -H "X-Bmob-Application-Id: Your Application ID" \
    -H "X-Bmob-REST-API-Key: Your REST API Key" \
    -G \
    --data-urlencode 'sum=score1,score2&groupby=createdAt,playerName&order=-_sumscore1' \
    https://api.bmob.cn/1/classes/GameScore

[
    {
        "_sumScore1": 399,
        "_sumScore2": 120,
        "playerName": "John"
        "createdAt": "2014-02-05"
    },
    {
        "_sumScore1": 299,
        "_sumScore2": 250,
        "playerName": "Bily"
        "createdAt": "2014-02-05"
    },
    {
        "_sumScore1": 99,
        "_sumScore2": 450,
        "playerName": "John"
        "createdAt": "2014-02-01"
    },
]

link http://docs.bmob.cn/data/Restful/b_developdoc/doc/index.html

After hours of looking, the only solution i found is to get all rows and do distinct by yourself.

To get all rows, beyond the limit of 1000, and the skip limit of 10000, this is a great solution.
http://cyber-duck.github.io/2016/03/18/how-to-retrieve-all-objects-on-parse-without-api-limitation/

@davimacedo We could have some query parameters to select distinct values, no? What do you think?

I think the API suggested in the beginning of the thread would be good:
curl -X GET \
-H "X-Parse-Application-Id: REDACTED" \
-H "X-Parse-REST-API-Key: REDACTED" \
-G \
--data-urlencode 'distinct=score' \
https://api.parse.com/1/classes/GameScore

We would have to handle this in ClassesRouter -> rest -> RestQuery -> DataBaseController -> Mongo and Postrgres adapters.

For mongo we can implement it using https://docs.mongodb.com/manual/reference/method/db.collection.distinct/.

For postgres using SELECT DISTINCT ... (https://www.postgresql.org/docs/9.0/static/sql-select.html)

I've just added it to my personal kanban. I can try to write something soon.

We really need this

Closes #2238 Via #4207

Does the new aggregate queries support pointers?

I don鈥檛 think so. But it does support dot notation. Feel free to open a PR, we鈥檒l review it. You could do distinct(PointerField.objectId) but that鈥檚 just a workaround

yeah I tried your suggestion before (pointer.objectId) before but no results

It鈥檚 up for the taking 馃槈

Was this page helpful?
0 / 5 - 0 ratings