# Storing a sorted list

**URL:** <https://discuss.dgraph.io/t/storing-a-sorted-list/2199>\
**Category:** Users\
**Created:** [February 3, 2018, 12:39pm UTC](https://discuss.dgraph.io/t/storing-a-sorted-list/2199 "2018-02-03T12:39:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smkhalsa](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/smkhalsa/32/1077_2.png) [@smkhalsa](https://discuss.dgraph.io/u/smkhalsa)\
**Post date:** [February 3, 2018, 12:39pm UTC](https://discuss.dgraph.io/t/storing-a-sorted-list/2199/1 "2018-02-03T12:39:42Z")

</div>

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:

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

```

It says [in the docs](https://docs.dgraph.io/query-language/#pagination) 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?

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [February 5, 2018, 1:19am UTC](https://discuss.dgraph.io/t/storing-a-sorted-list/2199/2 "2018-02-05T01:19:02Z")

</div>

> [@smkhalsa](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [March 7, 2018, 1:19am UTC](https://discuss.dgraph.io/t/storing-a-sorted-list/2199/3 "2018-03-07T01:19:14Z")

</div>

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