Remove cdt bin if element removal results in empty cdt

I think the title concisely describes what I’m looking for but I’ll also give some pseudocode and make sure this is actually a problem.

So I want to do this

aerospike.operate(
  key,
  [
    remove_from_list_bin(...),
    if_list_empty_after_removal_remove_list_bin(...)
  ]
)

but I don’t believe there’s a way to check for emptiness after an operation?

Now I could do this

try:
  aerospike.operate(
    key,
    [
      remove_from_list_bin(...),
      remove_list_bin(...)
    ],
    expressions=[if removing from list bin results in emtpy list then True]
  )
except FilteredOut:
  aerospike.remove_from_list_bin(...)

or (better) just this

aerospike.remove_from_list_bin(...)
aerospike.remove_list_bin(expressions=[if list bin is empty then True])

but I want to avoid the multiple calls without using a UDF, for lists and maps.

Am I missing something? Is there already a better way to do this in a single transaction (again, without a UDF)? Is mixing expressions into operations already possible or is this a feature that’s come up before?

Thanks!

Hey Avi, Unless anything changes, as of next version (5.6) you would be able to use the write-exp follow the removal to check if the CDT is empty and return nil to delete it. But atm UDF is the way to go about it.

Cheers

1 Like

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