Query that returns last 50 records in ascending order
  • I want a query to return the last 50 chat messages in my g2g app to display on the chat screen.  First thought is to have the apstrata query sort by the message schema's timestamp field in descending order and then have the iOS client re-sort the array in timestamp ascending order.  Thought I would reach out to see if there was a way to have the apstrata query return the last 50 records in ascending order and avoid having to do anything client side.


  • Hello Pete,

    To my knowledge this is not doable using an Apstrata query. If you want to keep it on the server-side and avoid sorting on the client, you still can create a server-side script that will issue the query, sort your result set and send it to the client.

    However, if you can set a date/time where your request can start from, then what you can do from you client is to issue a request as follows:

    query: apsdb.creationTime<date> >= "yyyy-mm-dd" (replace with some date/time)
    apsdb.sort: apsdb.creationTime<date:ASC>
    apsdb.queryFields: "*"

    This will work.

    You can apply the same technique using another field (not necessarily the creation time), since the trick is to have two references to sort with.

    Karim
  • Querying based on the date will not work since the dates of the last 50 messages in a particular group chat could be from a year ago or earlier that day.  Like you said I can either sort the query results server-side or client side.


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!