# How "key" is determined in as.NewKey in aerospike

**URL:** <https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413>\
**Category:** Go Client\
**Tags:** key\
**Created:** [August 2, 2018, 11:51am UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413 "2018-08-02T11:51:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 2, 2018, 11:51am UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/1 "2018-08-02T11:51:14Z")

</div>

I have been trying to update records in Aerospike.

I used key as below -

```auto
key, err := as.NewKey("fooBar", "users", res.Record.Bins["Email"])
if err != nil {
	result = map[string]string{"error": "Can't update key! Try again " + err.Error()}
	break
}

```

I have index maintained as `Email` on my namespace `fooBar` and sets `users`.

But, whenever I am updating data based on this key. It always inserts new and when using `as.UPDATE_ONLY` policy, it gives error `Key not found`

I inserted data using key `ID` column, I have in my `users` set, but since, I have `Email` as index too, Can’t I insert it using same `index`?

Thanks

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 2, 2018, 12:28pm UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/2 "2018-08-02T12:28:34Z")

</div>

No.

Aerospike is like a massive hash table, and does not work like a SQL database. A Key is a hash of what you pass to the `NewKey` function, and has nothing to do with any bins in the record.

Either use the (normalized) `email` as the key instead of `ID` (recommended), or first find the record via a query, extract its key, and then use it to change other bins in the same record. (not recommended, since it does not scale well)

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 2, 2018, 12:35pm UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/3 "2018-08-02T12:35:08Z")

</div>

Yes finding the key and using it is not a viable option especially at large user base. And I don’t have `ID` to use it for the purpose of update.

So, I believe my option is to use the (normalized) `email` as the key, but I can’t find any documentation about it.

Can you please provide the resource URL for using the `normalized` option you have mentioned above.

Thanks

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 2, 2018, 12:48pm UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/4 "2018-08-02T12:48:01Z")

</div>

Normalization in this scope means that you should convert the email to lower case, remove the white space around it, etc. to make sure you always end up with the same key.

There’s no special trick to it 🙂

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 2, 2018, 12:59pm UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/5 "2018-08-02T12:59:05Z")

</div>

Got it. Will do something similar now.

Thanks (y)

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [August 8, 2018, 12:59pm UTC](https://discuss.aerospike.com/t/how-key-is-determined-in-as-newkey-in-aerospike/5413/6 "2018-08-08T12:59:08Z")

</div>

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