Create vs Update operations


#1

Increment operator functions as follows:

input: op.incr('bin',1) if the bin doesn’t exists, create bin and put value as 1 else update bin’s value as +1

This works fine. But the callback value that i get for the operations is not unique to the operation. Or is it and i am unable to identify the same?


#2

When you say, callback value for the operation, which is the value under consideration. The callback signature is function(err, bins, metadata, key)

err - err.code == AEROSPIKE_OK, signifies the success/failure of the operate call. bins - If there is a read operation specified in the operation array, an example op.read('bin1') then the updated value of bin1 is returned. If there’s no read operation specified, then no bins will be retrieved.

metadata - contains ttl and generation of the record. Returned when there is atleast one read operation. key: Key of the record, returned always.

Hope this extra information helps. But if you can give us more details about which callback value we are talking about, that would be great.


#3

Hi Gayathri,

The issue that i am facing is that neither the err, bin value or metadata returned is different for the cases of a new value insert vs update.


#4

Hi Vikram,

We do not have a way differentiate between an update and new write in operate function call. But we have a work around for this. You can specify a read operation of the bin you are operating on. If your application logic can differentiate between update and a write, reading the bin that’s operated on would be a solution.


#5

Is there no other way? For now i have handled it in application logic itself, but a better callback is preferable.

Thanks for the clarification :smile:


#6

Hi Vikram,

We don’t have any other way :slight_smile: