If I run this code, it increments whatever the value is present at Index 7, if any of the index before 7 are not present, it simply puts NIL as its value
Code
Operation operation = ListOperation.increment( "incre", 7 );
client.operate( policy, key, operation );
AQL
aql> select * from test.users
+----+----------------------------------------+
| PK | incre |
+----+----------------------------------------+
| 2 | LIST('[1, 1, 1, 2, 1, 1, NIL, 1]') |
+----+----------------------------------------+
1 row in set (0.095 secs)
As you can see, index 6 didn't exist, so aerospike automatically put NIL in its place. If I try to increment index 6, I get this error.
Exception in thread "main" com.aerospike.client.AerospikeException: Error 4,1,30000,0,0,BB955892AFD8CA0 127.0.0.1 3000: Parameter error
My questions :-
1) Is it possible to put any sort of default value instead of NIL for indexes which dont exist? If there is no way to check for NIL, is it possible to increment NIL?
2) Is there a way to check for NIL value before incrementing it?
Increment operation assumes that the data type is integer. So, when you try to increment at position 7, and there is no element there yet, it starts with integer 0 and increments to 1. However, as you noticed, 6th position is filled with NIL as the list needs to be continuous. Now the problem is that NIL is not an integer. So, you cannot increment it.
To answer your specific questions: