# Badger example with prefix?

**URL:** <https://discuss.dgraph.io/t/badger-example-with-prefix/4101>\
**Category:** Badger\
**Created:** [February 26, 2019, 1:10am UTC](https://discuss.dgraph.io/t/badger-example-with-prefix/4101 "2019-02-26T01:10:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![awillis](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/awillis/32/1533_2.png) [@awillis](https://discuss.dgraph.io/u/awillis)\
**Post date:** [February 26, 2019, 1:10am UTC](https://discuss.dgraph.io/t/badger-example-with-prefix/4101/1 "2019-02-26T01:10:43Z")

</div>

I’m looking for an example of how to set and iterate over a data using prefixes. Could someone please point me in the right direction?

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [February 26, 2019, 6:53am UTC](https://discuss.dgraph.io/t/badger-example-with-prefix/4101/2 "2019-02-26T06:53:32Z")

</div>

See: [GitHub - dgraph-io/badger: Fast key-value DB in Go.](https://github.com/dgraph-io/badger#prefix-scans)

---

<div class="post-metadata">

**Author:** ![awillis](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/awillis/32/1533_2.png) [@awillis](https://discuss.dgraph.io/u/awillis)\
**Post date:** [February 27, 2019, 2:18am UTC](https://discuss.dgraph.io/t/badger-example-with-prefix/4101/3 "2019-02-27T02:18:51Z")

</div>

> <https://github.com/awillis/sluus/blob/master/processor/queue.go#L123>

The prefix key used in the example casts a string as a byte array. I’m using binary.LittleEndian.PutUint64 to create byte arrays from uint64 values. I can store the data, but prefix scans don’t return any data. I didn’t want to have to use a string as a prefix key.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [February 27, 2019, 3:22am UTC](https://discuss.dgraph.io/t/badger-example-with-prefix/4101/4 "2019-02-27T03:22:07Z")

</div>

Someone else can probably help you better, but generally speaking, you’d use a BigEndian encoding for Uint64s so they maintain their order when sorted lexicographically.
