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

I have been trying to update records in Aerospike.

I used key as below -

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

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)

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

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 :slight_smile:

Got it. Will do something similar now.

Thanks (y)

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