Writing `aerospike.null()` to map doesn't remove item from map

repro with aerospike:ce-5.7.0.16, python 3.9.11 and python aerospike library 7.0.1

import aerospike
from aerospike_helpers.operations import map_operations

ac = aerospike.client({'hosts': [('localhost', 3000)]})
ac.connect()
key = ('test', 'test', 'test')
try:
    ac.remove(key)
except:
    pass
ac.put(key, {'map': {'key': 'value'}})

print(ac.get(key)[2])
ac.operate(
    key,
    [
        map_operations.map_put(
            bin_name='map',
            key='key',
            value=aerospike.null())]
)
print(ac.get(key)[2])

prints

{'map': {'key': 'value'}}
{'map': {'key': None}}

i know there’s the remove operation but it makes using map_put_items less ergonomic for many map put ops (when some are removals), also i imagined the map items would behave similarly to bins (being removable with aerospike.null()) but maybe this isn’t justified?

You are correct that Map elements behave differently from bins in that you can store a null value in them. While a record can be viewed as a map of bins, there are differences in bins and Map elements (such as here). If you need to remove Map keys in the same request, you can specify those keys in map_remove_by_key_list operation in the same operate request.

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