Parse-sdk-js: Ordering data with ascending() on a pointer objects sub-field

Created on 11 Sep 2019  路  7Comments  路  Source: parse-community/Parse-SDK-JS

I understand it is possible to order by a field in a pointer, in my case I have a date field in a pointer and I would like to order by it using .ascending() I am trying with dot notation as i have read that is the correct usage but still no dice 'eventPointer.startDate' it does not order anything by date

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : "3.5.0",
    • Operating System: OSX/Debian
    • Hardware: Macbook
    • Localhost or remote server? Local, Google App Engine
  • JS SDK

    • JS SDK version: "2.4.0",
    • Application? node

let myEvents = await new Parse.Query(AttendIntent) .equalTo("userId", user.id) .include('eventPointer') .select('eventPointer.startDate') .ascending('eventPointer.startDate') .find(masterKey)

Seems to be similar https://github.com/parse-community/Parse-SDK-JS/issues/235

feature

Most helpful comment

its now 2020. i do really want this feature.

All 7 comments

This currently isn't implemented. As a workaround you can do the sorting after you retrieve all the objects.

The reason why is handleInclude

  1. Find all objects
  2. Get pointer ids from step 1 and query all the include pointers.
  3. Return objects

Sorting happens in step 1, you don't have any pointer values until after step 2.

To get what you want working, you would have to add custom sort after step 2 since you now have all included values.

Would you like to open a PR? I know this has been a highly requested feature.

@acinader @davimacedo Thoughts?

A PR regarding this would be very welcome for sure, but not so easy to be done.

In the meantime, you can use aggregation to perform this query.

@REPTILEHAUS Here is an example for sorting pointer values using aggregates.

I also have issue with this one that I resorted to using mongoDB driver to achieve this like what @dplewis mentioned. There's also performance problem when doing manual sorting with pagination.

If you are interested I added a custom sort to the Local Datastore queries.

https://github.com/parse-community/Parse-SDK-JS/blob/master/src/ParseQuery.js#L142

You can use that as a reference to implement this feature. It works with ascending / addAscending multiple sorts. More test cases would be needed but seems solid

I did something similar but struggling with large dataset because where doing it manually rather than with database. That's why I'm bypassing Parse and use aggregate instead in MongoDB Driver.

its now 2020. i do really want this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adrianchifor picture adrianchifor  路  3Comments

bezi picture bezi  路  4Comments

lamualfa picture lamualfa  路  5Comments

Jonarod picture Jonarod  路  6Comments

dplewis picture dplewis  路  7Comments