# Atomic Operations on List and Map Data Types - C, Java, and Go clients

**URL:** <https://discuss.aerospike.com/t/atomic-operations-on-list-and-map-data-types-c-java-and-go-clients/332>\
**Category:** Data Types\
**Tags:** go\
**Created:** [August 26, 2014, 10:26pm UTC](https://discuss.aerospike.com/t/atomic-operations-on-list-and-map-data-types-c-java-and-go-clients/332 "2014-08-26T22:26:21Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mingfai](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@mingfai](https://discuss.aerospike.com/u/mingfai)\
**Post date:** [August 31, 2014, 1:35am UTC](https://discuss.aerospike.com/t/atomic-operations-on-list-and-map-data-types-c-java-and-go-clients/332/3 "2014-08-31T01:35:19Z")

</div>

Thx for the hints. I also think there is a need for such API, and I saw at least one [another thread](http://discuss.aerospike.com/t/increasing-maximum-number-of-bins-per-namespace/169/3) someone asked about this feature.

With your hints and some reading on the [UDF developer guide] ([http://www.aerospike.com/docs/udf/udf\_guide.html](http://www.aerospike.com/docs/udf/udf_guide.html)), I am able to develop a Lua UDF that meet my need. As an example for other people who may be interested, details are as follows:

- map\_ext.lua

```auto
function putAll(rec, bin, val)
    local m1 = rec[bin]
    if m1==nil then m1 = map() end
    local m2 = val
    local m3 = map.merge( m1, m2, function(v1, v2)
        return v2
    end )
    rec[bin] = m3
    info("putAll() - m1: %s, m2: %s, m3: %s", tostring(m1), tostring(m2), tostring(m3))

    if aerospike:exists(rec) then aerospike:update(rec) else aerospike:create(rec) end
end

```

- Register with AQL

```auto
  register module 'map_ext.lua'

```

- Call in Java as

```auto
        client.execute(
                new WritePolicy(),
                new Key("MyNameSpace", "MySet", "MyRecordKey"),
                "map_ext", "putAll",
                Value.get("MyBinName"),
                Value.getAsMap(new HashMap() {{
                    put("A", 1);
                    put("B", 2);
                }}));

```

- some hints:
  - read the developer guide, esp the best practice section. it mentioned about disable lua cache, and the registered lua script will show up at “/opt/aerospike/usr/udf/lua” by default. Using splitted windows to edit and execute the code.
  - for Java, there is a com.aerospike.examples.UserDefinedFunction example that show how to call UDF

---

_[View the full topic](https://discuss.aerospike.com/t/atomic-operations-on-list-and-map-data-types-c-java-and-go-clients/332)._
