Atomic increment for nested map

Hey, currently on Aerospike Java client we support increment for maps using MapOperation.increment(mapPolicy, bin, mapKey, value) → Map<Long, Long>

is there someway we can increment a nested map Map<Long, Map<Long, Long>> MapOperation.increment(mapPolicy, bin, mapKey, mapSecondKey, value)

If something like this doesn’t exist yet, would udf be another way of handling these?

I tried the following command and that didn’t work either MapOperation.put(mapPolicy, “map”, Value.get(“count”), Value.get(10), CTX.mapKey(Value.get(“123”))))

and I get the following error : com.aerospike.client.AerospikeException: Error 26,1,30000,5000,1,BB9979897BC230A 3000: Operation not applicable

Yes, but it will depend on the version of the Java client and Aerospike server that you are running.

The MapOperation.increment in the current Java version (5.0.2) supports passing a context to find the element to apply the operation to.

Aerospike introduced support for nested List/Map update operations via context parameter.

Aerospike introduced support for nested List/Map operations via context parameter that can create the elements in the context path (similar to mkdir -p).

I updated to 5.0.2 when I got the error that operation is not supported

Is there a top level map key of “123”? Since you mention they are Long keys, did you mean Value.get(123), without the quotes?

You are correct. I double checked the method expected structure : {321={123=100}}


following the example from here : MapOperation (aerospike-client 5.0.3 API)…-

The aerospike server version is and client version is 5.0.2.

@kporter are there are examples to compare what might be wrong here?

That should work if the top level key 321 already exist.

If I use increment instead of put, do both keys still need to exist? For regular maps if key doesn’t exist MapOperation.increment creates the key. Should it work the same way for nested maps?

You have to specify a context flag for that to happen. That has been implemented since I’m not sure how to do that in Java but the context flag to create context (if it didn’t exist) should be there.

The Java APIs for context can be found here:

You would be interested in the APIs suffixed “create”.

Thank for all the help, it works now.

© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.