Best way to store bins with multiple values for one key in Aerospike


#1

I need to save the following format in Aerospike:

{"name": "interest",
"datamap" : [
  {"sports":"soccer"},
  {"color":"green"}],
"clientId":"100",
"eventTagId": 78932
}

Here clientId is a key. I can save name: interest for a single key(clientId) as ‘name’ will be the bin name and ‘interest’ will be its value. But, if I have a bin with multiple values for a single key like the following example:

datamap" : [
      {"sports":"soccer"},
      {"color":"green"}]

so how to store in Aerospike? I need a solution which does not give me hard time when I have to retrieve millions of records. I was thinking in a way to create another set for datamap with clientId as a key, and later perform JOIN operation on them. But I think it is an old relational DB solution. Your suggestions will be highly appreciated.


#2

If that’s your data model I’d save it in a single record with the bins name, datamap, clientId, and eventTagId. Aerospike supports the complex data types list and map, and the data of datamap is a map.

For example, this is how you do it in the Python client: http://www.aerospike.com/docs/client/python/usage/kvs/write.html

Because this isn’t SQL-land, your data doesn’t need to be two-dimensional with a join connecting two tables in a many-to-one relationship. You just put complex data in the bin of your record, no JOIN needed.