Changing the value of bin in a record of aerospike db which is of map type in lua script


say aerospike database is having recored data like below

let the namespace be employee

name age characteristics

sachin 25 MAP('{"weight":70, "height":25}')

now i want to change the value of height which is inside map for all the records in employee namespace through lua script.

i have tried for changing the bins of normal data type as below , i,e i tried to change the age as below:

function changeAgeOfEmployee(rec)     
         if not aerospike:exists(rec) then    
            error ("Invalid Record. Returning")    
            age = 30    
            rec['age'] = age    

but i am not sure how to change the value in map in lua, can somebody please assist me in this


Look at the Lua UDF API reference. Under Map there’s sample code in map.pairs() for accessing the keys of a map.

If you want to access a specific key of a map, you should be able to use rec['employee']['age'].


hi , thanks for the reply , i tried the same but it dint work


Did you try assigning to a local variable?

local employee = rec['employee']
employee['age'] = 79
rec['employee'] = employee

Also, you may need to check that those aren’t nil and have the correct type, that is employee should be a map.