# List storage objects in reverse order

**URL:** https://forum.heroiclabs.com/t/list-storage-objects-in-reverse-order/5640
**Category:** Runtime Framework
**Created:** [September 16, 2024, 9:47pm UTC](https://forum.heroiclabs.com/t/list-storage-objects-in-reverse-order/5640 "2024-09-16T21:47:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![thegoldenmule](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/thegoldenmule/32/2118_2.png) [@thegoldenmule](https://forum.heroiclabs.com/u/thegoldenmule)
#### Post date: [September 16, 2024, 9:47pm UTC](https://forum.heroiclabs.com/t/list-storage-objects-in-reverse-order/5640/1 "2024-09-16T21:47:01Z")

</div>

For each multiplayer match, we store a record of the results. Then a user can look back through previous matches. We’re just using the storage system for this, in go:

```auto
nk.StorageWrite(ctx, []*runtime.StorageWrite{
		{
			Collection: "matches",
			Key: matchId,
			Value: string(payload),
			PermissionRead: 0,
			PermissionWrite: 0,
			UserID: userId,
		},
	})

```

Then when we want to show match history, we use:

```auto
records, nextCursor, err := nk.StorageList(ctx, "", userId, "matches", 10, cursor)

```

However, while we’d like to show the most recent 10 matches, this shows the _first_ 10. Looking through the server runtime code in `core_storage.go`, it looks like there is no way to reverse the order of the cursors and the list queries.

This seems like a straightforward use case, so I thought I’d ask here if we’re missing something simple. If not, would the Heroic Labs team be open to a PR?

---

<div class="post-metadata">

### Author: ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)
#### Post date: [October 29, 2024, 4:20pm UTC](https://forum.heroiclabs.com/t/list-storage-objects-in-reverse-order/5640/2 "2024-10-29T16:20:29Z")

</div>

Hello @thegoldenmule,

The `StorageList` API doesn’t guarantee an ordering of the results - if you’re seeing an ordering it’s coincidental and that expectation may break sooner or later.

An option would be to create a [Storage Search index](https://heroiclabs.com/docs/nakama/concepts/storage/search/) and list ordering by create\_time.

Otherwise you’d have to store all the entries in a single storage object per user and manually update it with consistent ordering every time you add to it- but you’d have to cap it at some amount of entries otherwise it could grow too large.

Best.

---

<div class="post-metadata">

### Author: ![thegoldenmule](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/thegoldenmule/32/2118_2.png) [@thegoldenmule](https://forum.heroiclabs.com/u/thegoldenmule)
#### Post date: [December 4, 2024, 9:11pm UTC](https://forum.heroiclabs.com/t/list-storage-objects-in-reverse-order/5640/3 "2024-12-04T21:11:40Z")

</div>

Whoops, just saw this. Thanks for the info! Yah, strange, they have always returned ordered but I see in the SQL that it’s only ordering by key.
