Storing a sorted list


(Sat Mandir S Khalsa) #1

What’s the recommended way to store nodes with a default sort order? In my case I have a ‘workout’ node that has edges to many ‘exercise’ nodes. If I make the following query:

workout(func: uid(0xcceb)) {
  name@en
  exercise {
    name@en
  }
}

It says in the docs that:

Without a sort order specified, the results are sorted by uid, which is assigned randomly. So the ordering, while deterministic, might not be what you expected.

If the default sort order is based on UID as stated above, is there any way to ensure that UIDs are added sequentialy for a given set of nodes? Or will I need to add a “order” predicate to each node and apply a sort in my query?


(Pawan Rawal) #2

Its best to have a created_at value attached with the timestamp the exercise node is created at and sort by it.


(system) #3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.