Search code examples
dictionaryluaaerospike

Removing an object from a dictionary in lua


I am using aerospike for storage and its UDF's in Lua. While executing the udf's through both NodeJS and Python- I need to delete a key-value pair from the dictionary being passed as a parameter.

Below is the code snippets:

function deleteProduct(rec, prod_id, isodate)
    map.remove(rec, prod_id)
    aerospike:update(rec)
    return 0
end

And the rec structure is:

{
    meta.num_prod: 4
    s.10000006: {
      prod_id: "10000006"
      qty: "4"
 }

I do understand that pythonic dictionary is not same as Lua maps- but I am stuck with this. I get the error message as:

/opt/aerospike/usr/udf/lua/update.lua:14: bad argument #1 to \'remove\' (Map expected, got userdata)

The rec is the aerospike record being invoked in the below manner:

                var udf = { module:'update', funcname: 'deleteProductFromCart', args: [prod_key, isoDate]}
            sails.aerospike.execute(cart_key, udf, function(err, result) {
                if(err.code!=status.AEROSPIKE_OK){
                    console.log(err)
                    defer.resolve(false)
                }
                else{
                    defer.resolve(true)
                }
            });

Solution

  • Below works just fine!

     map[key] = nil