Map operations
Map operations read, update, and remove elements in map-type bins directly on the server.
Each operation is governed by a map policy (order, write flags, PERSIST_INDEX),
can target nested elements using a context,
and returns results controlled by a return type.
Map policy
The map policy defines the characteristics of a map write operation.
Map order
The map order is set in the map policy and determines the map subtype. The order type determines how the server accesses map elements:
- Unordered — no ordering guarantees. Key lookup is a linear scan. Lowest storage overhead.
- K-ordered — elements are maintained in key order. Key lookup uses binary search. Without a persisted index, the key offset index is built temporarily per operation at O(N) cost.
- KV-ordered — elements are maintained in key and value order. Without a persisted full index, rank and value lookups use the same heap/scan fallback as K-ordered (the value order index is not built on-demand). With a persisted full index, rank lookups are O(1) and value searches are O(log N).
Use set_type() to convert between order types.
See Map performance for the operational complexity of each order type.
Persisting the map index
For large maps with a high read-to-write ratio, rebuilding the offset index
on every access can consume significant CPU. Setting PERSIST_INDEX in the
map policy stores the index on disk inside the map particle, so subsequent
operations load it directly instead of rebuilding it.
PERSIST_INDEX is set per write and applies only to the top-level map, not nested maps.
Setting PERSIST_INDEX on an unordered map sorts its keys into key order and
persists the offset index, giving it the same binary-search key lookup behavior
as a K-ordered map with a persisted index (column 3 in the
performance table).
Write flags
| Flag | Description |
|---|---|
MODIFY_DEFAULT | Default: upserts; create or update map keys |
CREATE_ONLY | Only create new map keys. Fail if the key already exists |
UPDATE_ONLY | Only update existing map keys. Fail if a key does not exist |
NO_FAIL | No-op instead of fail if a policy violation occurred, such as CREATE_ONLY |
DO_PARTIAL | When used with NO_FAIL, add elements that did not violate a policy |
Write flags can be combined using bitwise OR. For example, UPDATE_ONLY | NO_FAIL | DO_PARTIAL
updates existing keys, skips keys that do not exist, and applies the remaining updates without failing.
Context
| Context Type | Description |
|---|---|
MAP_INDEX | Finds an element in a Map by index. A negative index is a lookup performed in reverse from the end of the map. If it is out of bounds, a parameter error is returned. |
MAP_KEY | Finds an element in a Map by key. |
MAP_RANK | Finds an element in a Map by rank. A negative rank is a lookup performed in reverse from the highest ranked. |
MAP_VALUE | Finds an element in a Map by value. |
MAP_KEY_CREATE | Finds an element in a Map by key. Creates the element if it does not exist. |
The context is a list of element selectors describing a path to the nested map element where the operation should be applied. Without a context it is assumed that the operation occurs at the top level of the map.
Return types
| Return Type | Description |
|---|---|
KEY | The key of the element (in single result operations) or elements (in multi result operations) |
VALUE | The value of the element (in single result operations) or elements (in multi result operations) |
KEY_VALUE | The key/value pair of the element (in single result operations) or elements (in multi result operations) |
ORDERED_MAP | Returns results as an ordered Map |
UNORDERED_MAP | Returns results as an unordered Map |
NONE | Nothing is returned. It speeds up remove operations by not constructing a reply |
COUNT | Number of elements returned |
INDEX | Key order position of the element, from 0 (smallest key) to N-1 (largest) |
REVERSE_INDEX | Reverse key order position of the element, from 0 (largest key) to N-1 (smallest) |
RANK | Value order of the element, with 0 being the smallest value |
REVERSE_RANK | Reverse value order of the element, with 0 being the largest value |
INVERTED | Invert meaning of map command and return values. Combine with another return type using bitwise OR, such as `COUNT |
EXISTS | Returns a boolean true if any elements match the criteria. For example, get_all_by_value with EXISTS returns true if the value is in the map. |
Examples
- Remove the 10 map elements with the largest key values:
remove_by_index_range(-10, 10, NONE) - Remove all but the 10 map elements with the largest key values:
remove_by_index_range(-10, 10, NONE | INVERTED) - Keep only the top 10 key elements and return the count of removed elements:
remove_by_index_range(-10, 10, COUNT | INVERTED)
Modify operations
clear(binName[, ctx])Clears the map. Map type stays the same.
null
// m = {a: 1, b: 2, c: 3}
client.operate(null, key, MapOperation.clear("m"));// m == {}# m = {a: 1, b: 2, c: 3}
client.operate(key, [ map_operations.map_clear("m")])# m == {}// m = {a: 1, b: 2, c: 3}
_, err := client.Operate(nil, key, as.MapClearOp("m"),)// m == {}// m = {a: 1, b: 2, c: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_clear(&ops, "m", NULL);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// m == {}// m = {a: 1, b: 2, c: 3}
client.Operate(null, key, MapOperation.Clear("m"));// m == {}// m = {a: 1, b: 2, c: 3}
const maps = Aerospike.maps
await client.operate(key, [ maps.clear('m')])// m == {}decrement(mapPolicy, binName, key, delta[, ctx])Decrements values by delta-value for all items identified by key.
Only works for integer or float value types in the {key: value} pair. If the bin does not exist, a new unordered map is created unless a different map order is specified through the map policy.
Type interaction between value and delta-value
| Value-Type | Delta: integer | Delta: float |
|---|---|---|
Map Entry: integer | Subtract normally | Truncate to nearest integer and subtract |
Map Entry: float | Convert integer to float and subtract | Subtract normally |
New value after decrement
// m = {a: 1, b: 10, c: 3}// decrement is deprecated; use increment with negative value
Record record = client.operate(null, key, MapOperation.increment(MapPolicy.Default, "m", Value.get("b"), Value.get(-3)));// returns 7 (new value of key "b")// m == {a: 1, b: 7, c: 3}# m = {a: 1, b: 10, c: 3}
_, _, bins = client.operate(key, [ map_operations.map_decrement("m", "b", 3)])# bins["m"] == 7 (new value of key "b")# m == {a: 1, b: 7, c: 3}// m = {a: 1, b: 10, c: 3}
record, err := client.Operate(nil, key, as.MapDecrementOp(as.DefaultMapPolicy(), "m", "b", 3),)// record.Bins["m"] == 7// m == {a: 1, b: 7, c: 3}// m = {a: 1, b: 10, c: 3}
as_map_policy mp;as_map_policy_init(&mp);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_decrement(&ops, "m", NULL, &mp, (as_val*)as_string_new("b", false), (as_val*)as_integer_new(3));
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 7 (new value of key "b")// m = {a: 1, b: 10, c: 3}// Decrement is deprecated; use Increment with negative value
Record record = client.Operate(null, key, MapOperation.Increment(MapPolicy.Default, "m", Value.Get("b"), Value.Get(-3)));// returns 7 (new value of key "b")// m == {a: 1, b: 7, c: 3}// m = {a: 1, b: 10, c: 3}// decrement is deprecated; use increment with negative value
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.increment('m', 'b', -3)])// result.bins.m == 7// m == {a: 1, b: 7, c: 3}increment(mapPolicy, binName, key, delta[, ctx])Increments values by delta-value for all items identified by key.
Only works for integer or float value types in the {key: value} pair. If the bin does not exist, a new unordered map is created unless a different map order is specified through the map policy.
Type interaction between value and delta-value
| Value-Type | Delta: integer | Delta: float |
|---|---|---|
Map Entry: integer | Add normally | Truncate to nearest integer and add |
Map Entry: float | Convert integer to float and add | Add normally |
New value after increment
// m = {a: 1, b: 2, c: 3}
Record record = client.operate(null, key, MapOperation.increment(MapPolicy.Default, "m", Value.get("b"), Value.get(10)));// returns 12 (new value of key "b")// m == {a: 1, b: 12, c: 3}# m = {a: 1, b: 2, c: 3}
_, _, bins = client.operate(key, [ map_operations.map_increment("m", "b", 10)])# bins["m"] == 12 (new value of key "b")# m == {a: 1, b: 12, c: 3}// m = {a: 1, b: 2, c: 3}
record, err := client.Operate(nil, key, as.MapIncrementOp(as.DefaultMapPolicy(), "m", "b", 10),)// record.Bins["m"] == 12// m == {a: 1, b: 12, c: 3}// m = {a: 1, b: 2, c: 3}
as_map_policy mp;as_map_policy_init(&mp);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_increment(&ops, "m", NULL, &mp, (as_val*)as_string_new("b", false), (as_val*)as_integer_new(10));
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 12 (new value of key "b")// m = {a: 1, b: 2, c: 3}
Record record = client.Operate(null, key, MapOperation.Increment(MapPolicy.Default, "m", Value.Get("b"), Value.Get(10)));// returns 12 (new value of key "b")// m == {a: 1, b: 12, c: 3}// m = {a: 1, b: 2, c: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.increment('m', 'b', 10)])// result.bins.m == 12// m == {a: 1, b: 12, c: 3}put_items(mapPolicy, binName, items[, ctx])Creates a map bin with a specified order, if the bin does not exist. Takes a map of key/value items and adds them to the map bin.
The element count of the map after the operation, in the ‘bins’ part of the record under the bin name.
If the bin does not exist, a new unordered map is created unless a different map order is specified through the map policy.
K_ORDERED maps are preferred over UNORDERED maps, with no real disadvantage in terms of space used.
// m = {a: 1}
Map<Value, Value> items = new HashMap<>();items.put(Value.get("b"), Value.get(2));items.put(Value.get("c"), Value.get(3));
Record record = client.operate(null, key, MapOperation.putItems(MapPolicy.Default, "m", items));// returns 3 (new map size)// m == {a: 1, b: 2, c: 3}# m = {a: 1}
_, _, bins = client.operate(key, [ map_operations.map_put_items("m", {"b": 2, "c": 3})])# bins["m"] == 3 (new map size)# m == {a: 1, b: 2, c: 3}// m = {a: 1}
items := map[interface{}]interface{}{ "b": 2, "c": 3,}record, err := client.Operate(nil, key, as.MapPutItemsOp(as.DefaultMapPolicy(), "m", items),)// record.Bins["m"] == 3// m == {a: 1, b: 2, c: 3}// m = {a: 1}
as_map_policy mp;as_map_policy_init(&mp);
as_hashmap items;as_hashmap_init(&items, 2);as_stringmap_set_int64(&items, "b", 2);as_stringmap_set_int64(&items, "c", 3);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_put_items(&ops, "m", NULL, &mp, (as_map*)&items);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 3 (new map size)// m = {a: 1}
Dictionary<Value, Value> items = new Dictionary<Value, Value> { { Value.Get("b"), Value.Get(2) }, { Value.Get("c"), Value.Get(3) }};
Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, "m", items));// returns 3 (new map size)// m == {a: 1, b: 2, c: 3}// m = {a: 1}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.putItems('m', { b: 2, c: 3 })])// result.bins.m == 3// m == {a: 1, b: 2, c: 3}put(mapPolicy, binName, key, value[, ctx])Creates a map bin with a specified order, if the bin does not exist. Adds a key/value element to the map.
The element count of the map after the operation, in the ‘bins’ part of the record under the bin name.
If the bin does not exist, a new unordered map is created unless a different map order is specified through the map policy.
K_ORDERED maps are preferred over UNORDERED maps, with no real disadvantage in terms of space used.
With a persisted index, ordered maps have 𝓞(log N) worst-case performance. Without a persisted index or for unordered maps, the worst-case performance is 𝓞(N). See Map performance.
// m = {a: 1}
Record record = client.operate(null, key, MapOperation.put(MapPolicy.Default, "m", Value.get("b"), Value.get(2)));// returns 2 (new map size)// m == {a: 1, b: 2}# m = {a: 1}
_, _, bins = client.operate(key, [ map_operations.map_put("m", "b", 2)])# bins["m"] == 2 (new map size)# m == {a: 1, b: 2}// m = {a: 1}
record, err := client.Operate(nil, key, as.MapPutOp(as.DefaultMapPolicy(), "m", "b", 2),)// record.Bins["m"] == 2// m == {a: 1, b: 2}// m = {a: 1}
as_map_policy mp;as_map_policy_init(&mp);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_put(&ops, "m", NULL, &mp, (as_val*)as_string_new("b", false), (as_val*)as_integer_new(2));
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 2 (new map size)// m = {a: 1}
Record record = client.Operate(null, key, MapOperation.Put(MapPolicy.Default, "m", Value.Get("b"), Value.Get(2)));// returns 2 (new map size)// m == {a: 1, b: 2}// m = {a: 1}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.put('m', 'b', 2)])// result.bins.m == 2// m == {a: 1, b: 2}remove_by_key_list(binName, keys, returnType[, ctx])Remove all {key: value} pairs where map.key ∈ keyList.
Multi result
Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
List<Value> keys = Arrays.asList(Value.get("a"), Value.get("c"), Value.get("e"));Record record = client.operate(null, key, MapOperation.removeByKeyList("m", keys, MapReturnType.KEY_VALUE));// returns {a: 1, c: 3, e: 5}// m == {b: 2, d: 4}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_key_list("m", ["a", "c", "e"], aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("a", 1), ("c", 3), ("e", 5)]# m == {b: 2, d: 4}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapRemoveByKeyListOp("m", []any{"a", "c", "e"}, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{a: 1}, {c: 3}, {e: 5}]// m == {b: 2, d: 4}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_arraylist keys;as_arraylist_init(&keys, 3, 0);as_arraylist_append_str(&keys, "a");as_arraylist_append_str(&keys, "c");as_arraylist_append_str(&keys, "e");
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_key_list(&ops, "m", NULL, (as_list*)&keys, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{a: 1}, {c: 3}, {e: 5}]// m == {b: 2, d: 4}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
IList keys = new List<Value> { Value.Get("a"), Value.Get("c"), Value.Get("e")};Record record = client.Operate(null, key, MapOperation.RemoveByKeyList("m", keys, MapReturnType.KEY_VALUE));// returns {a: 1, c: 3, e: 5}// m == {b: 2, d: 4}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByKeyList('m', ['a', 'c', 'e'], maps.returnType.KEY_VALUE)])// result.bins.m == [{a: 1}, {c: 3}, {e: 5}]// m == {b: 2, d: 4}remove_by_value_list(binName, values, returnType[, ctx])Remove all {key: value} pairs where map.value ∈ valueList.
Multi result
Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
List<Value> values = Arrays.asList(Value.get(2), Value.get(4));Record record = client.operate(null, key, MapOperation.removeByValueList("m", values, MapReturnType.KEY));// returns [b, d]// m == {a: 1, c: 3, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_value_list("m", [2, 4], aerospike.MAP_RETURN_KEY)])# bins["m"] == ["b", "d"]# m == {a: 1, c: 3, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapRemoveByValueListOp("m", []any{2, 4}, as.MapReturnType.KEY),)// record.Bins["m"] == ["b", "d"]// m == {a: 1, c: 3, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_arraylist values;as_arraylist_init(&values, 2, 0);as_arraylist_append_int64(&values, 2);as_arraylist_append_int64(&values, 4);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_value_list(&ops, "m", NULL, (as_list*)&values, AS_MAP_RETURN_KEY);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == ["b", "d"]// m == {a: 1, c: 3, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
IList values = new List<Value> { Value.Get(2), Value.Get(4) };Record record = client.Operate(null, key, MapOperation.RemoveByValueList("m", values, MapReturnType.KEY));// returns [b, d]// m == {a: 1, c: 3, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByValueList('m', [2, 4], maps.returnType.KEY)])// result.bins.m == ['b', 'd']// m == {a: 1, c: 3, e: 5}remove_by_value(binName, value, returnType[, ctx])Remove all {key: value} pairs where map.value == value.
Multi result
Requesting an INDEX return type adds 𝓞(N + M) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 1, d: 3}
Record record = client.operate(null, key, MapOperation.removeByValue("m", Value.get(1), MapReturnType.KEY));// returns [a, c] (keys of removed entries)// m == {b: 2, d: 3}# m = {a: 1, b: 2, c: 1, d: 3}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_value("m", 1, aerospike.MAP_RETURN_KEY)])# bins["m"] == ["a", "c"]# m == {b: 2, d: 3}// m = {a: 1, b: 2, c: 1, d: 3}
record, err := client.Operate(nil, key, as.MapRemoveByValueOp("m", 1, as.MapReturnType.KEY),)// record.Bins["m"] == ["a", "c"]// m == {b: 2, d: 3}// m = {a: 1, b: 2, c: 1, d: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_value(&ops, "m", NULL, (as_val*)as_integer_new(1), AS_MAP_RETURN_KEY);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == ["a", "c"]// m == {b: 2, d: 3}// m = {a: 1, b: 2, c: 1, d: 3}
Record record = client.Operate(null, key, MapOperation.RemoveByValue("m", Value.Get(1), MapReturnType.KEY));// returns [a, c]// m == {b: 2, d: 3}// m = {a: 1, b: 2, c: 1, d: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByValue('m', 1, maps.returnType.KEY)])// result.bins.m == ['a', 'c']// m == {b: 2, d: 3}remove_by_index_range(binName, index[, count], returnType[, ctx])Remove all {key: value} pairs where k = indexof(map.key) and k >= index and k < index + count. Omitting count select element(s) where k >= origin + index.
Multi result
Requesting a RANK return type adds 𝓞(N log N). Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
Record record = client.operate(null, key, MapOperation.removeByIndexRange("m", 1, 2, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m == {a: 1, d: 4, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
_, _, bins = client.operate(key, [ map_operations.map_remove_by_index_range("m", 1, 2, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]# m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
record, err := client.Operate(nil, key, as.MapRemoveByIndexRangeCountOp("m", 1, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_index_range(&ops, "m", NULL, 1, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
Record record = client.Operate(null, key, MapOperation.RemoveByIndexRange("m", 1, 2, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByIndexRange('m', 1, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}remove_by_index(binName, index, returnType[, ctx])Remove {key: value} entry where map.key is the ith smallest key where i == index.
Single result
Requesting a RANK return type adds 𝓞(N), or 𝓞(log N) with a persisted full index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3} (K_ORDERED)
Record record = client.operate(null, key, MapOperation.removeByIndex("m", 0, MapReturnType.KEY_VALUE));// returns {a: 1} (smallest key removed)// m == {b: 2, c: 3}# m = {a: 1, b: 2, c: 3} (K_ORDERED)
_, _, bins = client.operate(key, [ map_operations.map_remove_by_index("m", 0, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("a", 1)# m == {b: 2, c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
record, err := client.Operate(nil, key, as.MapRemoveByIndexOp("m", 0, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {a: 1}// m == {b: 2, c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_index(&ops, "m", NULL, 0, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == {a: 1}// m == {b: 2, c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
Record record = client.Operate(null, key, MapOperation.RemoveByIndex("m", 0, MapReturnType.KEY_VALUE));// returns {a: 1}// m == {b: 2, c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByIndex('m', 0, maps.returnType.KEY_VALUE)])// result.bins.m == {a: 1}// m == {b: 2, c: 3}remove_by_key_range(binName, keyBegin, keyEnd, returnType[, ctx])Remove all {key: value} pairs where map.key >= keyStart and map.key < keyStop. Omitting keyStop select element(s) where map.key >= keyStart.
Multi result
Requesting a RANK return type adds 𝓞(N log N). Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.operate(null, key, MapOperation.removeByKeyRange("m", Value.get("b"), Value.get("d"), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3} (keys >= "b" and < "d")// m == {a: 1, d: 4, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_key_range("m", "b", "d", aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]# m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapRemoveByKeyRangeOp("m", "b", "d", as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_key_range(&ops, "m", NULL, (as_val*)as_string_new("b", false), (as_val*)as_string_new("d", false), AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.Operate(null, key, MapOperation.RemoveByKeyRange("m", Value.Get("b"), Value.Get("d"), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByKeyRange('m', 'b', 'd', maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}remove_by_key_rel_index_range(binName, key, index[, count], returnType[, ctx])Remove all {key: value} pairs where origin = index(key), k = indexof(map.key) and k >= origin + index and k < origin + index + count. Omitting count select element(s) where k >= origin + index.
Multi result
// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// From key "b" (index 1), offset 0, count 3
Record record = client.operate(null, key, MapOperation.removeByKeyRelativeIndexRange("m", Value.get("b"), 0, 3, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3, d: 4}// m == {a: 1, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)# From key "b" (index 1), offset 0, count 3
_, _, bins = client.operate(key, [ map_operations.map_remove_by_key_index_range_relative("m", "b", 0, aerospike.MAP_RETURN_KEY_VALUE, count=3)])# bins["m"] == [("b", 2), ("c", 3), ("d", 4)]# m == {a: 1, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// From key "b" (index 1), offset 0, count 3
record, err := client.Operate(nil, key, as.MapRemoveByKeyRelativeIndexRangeCountOp("m", "b", 0, 3, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}, {d: 4}]// m == {a: 1, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// From key "b" (index 1), offset 0, count 3
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_key_rel_index_range(&ops, "m", NULL, (as_val*)as_string_new("b", false), 0, 3, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}, {d: 4}]// m == {a: 1, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// From key "b" (index 1), offset 0, count 3
Record record = client.Operate(null, key, MapOperation.RemoveByKeyRelativeIndexRange("m", Value.Get("b"), 0, 3, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3, d: 4}// m == {a: 1, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// From key "b" (index 1), offset 0, count 3
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByKeyRelIndexRange('m', 'b', 0, 3, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}, {d: 4}]// m == {a: 1, e: 5}remove_by_key(binName, key, returnType[, ctx])Remove entry {key: value} where map.key == key.
Single result
Requesting an INDEX return type adds 𝓞(N), or 𝓞(log N) with a persisted index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3}
Record record = client.operate(null, key, MapOperation.removeByKey("m", Value.get("b"), MapReturnType.VALUE));// returns 2 (removed value)// m == {a: 1, c: 3}# m = {a: 1, b: 2, c: 3}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_key("m", "b", aerospike.MAP_RETURN_VALUE)])# bins["m"] == 2# m == {a: 1, c: 3}// m = {a: 1, b: 2, c: 3}
record, err := client.Operate(nil, key, as.MapRemoveByKeyOp("m", "b", as.MapReturnType.VALUE),)// record.Bins["m"] == 2// m == {a: 1, c: 3}// m = {a: 1, b: 2, c: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_key(&ops, "m", NULL, (as_val*)as_string_new("b", false), AS_MAP_RETURN_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == 2// m == {a: 1, c: 3}// m = {a: 1, b: 2, c: 3}
Record record = client.Operate(null, key, MapOperation.RemoveByKey("m", Value.Get("b"), MapReturnType.VALUE));// returns 2// m == {a: 1, c: 3}// m = {a: 1, b: 2, c: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByKey('m', 'b', maps.returnType.VALUE)])// result.bins.m == 2// m == {a: 1, c: 3}remove_by_rank_range(binName, rank[, count], returnType[, ctx])Remove all {key: value} pairs where r = rankof(map.value) and r >= rank and r < rank + count. Omitting count select element(s) where r >= rank.
Multi result
Requesting an INDEX return type adds 𝓞(N log N) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
Record record = client.operate(null, key, MapOperation.removeByRankRange("m", 0, 2, MapReturnType.KEY_VALUE));// returns {b: 1, d: 2} (2 smallest values removed)// m == {a: 3, c: 5, e: 4}# m = {a: 3, b: 1, c: 5, d: 2, e: 4}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_rank_range("m", 0, 2, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 1), ("d", 2)]# m == {a: 3, c: 5, e: 4}// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
record, err := client.Operate(nil, key, as.MapRemoveByRankRangeCountOp("m", 0, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 1}, {d: 2}]// m == {a: 3, c: 5, e: 4}// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_rank_range(&ops, "m", NULL, 0, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 1}, {d: 2}]// m == {a: 3, c: 5, e: 4}// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
Record record = client.Operate(null, key, MapOperation.RemoveByRankRange("m", 0, 2, MapReturnType.KEY_VALUE));// returns {b: 1, d: 2}// m == {a: 3, c: 5, e: 4}// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByRankRange('m', 0, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 1}, {d: 2}]// m == {a: 3, c: 5, e: 4}remove_by_rank(binName, rank, returnType[, ctx])Remove {key: value} entry where map.value is the ith smallest value where i == rank.
Single result
Requesting an INDEX return type adds 𝓞(N) on an unordered map, or 𝓞(1) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 3, b: 1, c: 2}
Record record = client.operate(null, key, MapOperation.removeByRank("m", 0, MapReturnType.KEY_VALUE));// returns {b: 1} (smallest value removed)// m == {a: 3, c: 2}# m = {a: 3, b: 1, c: 2}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_rank("m", 0, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("b", 1)# m == {a: 3, c: 2}// m = {a: 3, b: 1, c: 2}
record, err := client.Operate(nil, key, as.MapRemoveByRankOp("m", 0, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {b: 1}// m == {a: 3, c: 2}// m = {a: 3, b: 1, c: 2}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_rank(&ops, "m", NULL, 0, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == {b: 1}// m == {a: 3, c: 2}// m = {a: 3, b: 1, c: 2}
Record record = client.Operate(null, key, MapOperation.RemoveByRank("m", 0, MapReturnType.KEY_VALUE));// returns {b: 1}// m == {a: 3, c: 2}// m = {a: 3, b: 1, c: 2}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByRank('m', 0, maps.returnType.KEY_VALUE)])// result.bins.m == {b: 1}// m == {a: 3, c: 2}remove_by_value_range(binName, valueBegin, valueEnd, returnType[, ctx])Remove all {key: value} pairs where map.value >= valueStart and map.value < valueStop. Omitting valueStop select element(s) where map.value >= valueStart.
Multi result
Requesting an INDEX return type adds 𝓞(N + M) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.operate(null, key, MapOperation.removeByValueRange("m", Value.get(2), Value.get(4), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3} (values >= 2 and < 4)// m == {a: 1, d: 4, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_remove_by_value_range("m", 2, 4, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]# m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapRemoveByValueRangeOp("m", 2, 4, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_value_range(&ops, "m", NULL, (as_val*)as_integer_new(2), (as_val*)as_integer_new(4), AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.Operate(null, key, MapOperation.RemoveByValueRange("m", Value.Get(2), Value.Get(4), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m == {a: 1, d: 4, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByValueRange('m', 2, 4, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]// m == {a: 1, d: 4, e: 5}remove_by_value_rel_rank_range(binName, value, rank[, count], returnType[, ctx])Remove all {key: value} pairs where origin = rank(value), r = rankof(map.value) and r >= origin + rank and r < origin + rank + count. Omitting count select element(s) where r >= origin + rank.
Multi result
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}// From value 3 (rank 2), offset 0, count 2
Record record = client.operate(null, key, MapOperation.removeByValueRelativeRankRange("m", Value.get(3), 0, 2, MapReturnType.KEY_VALUE));// returns {c: 3, d: 4}// m == {a: 1, b: 2, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}# From value 3 (rank 2), offset 0, count 2
_, _, bins = client.operate(key, [ map_operations.map_remove_by_value_rank_range_relative("m", 3, 0, aerospike.MAP_RETURN_KEY_VALUE, count=2)])# bins["m"] == [("c", 3), ("d", 4)]# m == {a: 1, b: 2, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}// From value 3 (rank 2), offset 0, count 2
record, err := client.Operate(nil, key, as.MapRemoveByValueRelativeRankRangeCountOp("m", 3, 0, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{c: 3}, {d: 4}]// m == {a: 1, b: 2, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}// From value 3 (rank 2), offset 0, count 2
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_remove_by_value_rel_rank_range(&ops, "m", NULL, (as_val*)as_integer_new(3), 0, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{c: 3}, {d: 4}]// m == {a: 1, b: 2, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}// From value 3 (rank 2), offset 0, count 2
Record record = client.Operate(null, key, MapOperation.RemoveByValueRelativeRankRange("m", Value.Get(3), 0, 2, MapReturnType.KEY_VALUE));// returns {c: 3, d: 4}// m == {a: 1, b: 2, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}// From value 3 (rank 2), offset 0, count 2
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.removeByValueRelRankRange('m', 3, 0, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{c: 3}, {d: 4}]// m == {a: 1, b: 2, e: 5}Read operations
get_by_key_list(binName, keys, returnType[, ctx])Get all {key: value} pairs where map.key ∈ keyList.
Multi result
Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
List<Value> keys = Arrays.asList(Value.get("a"), Value.get("c"), Value.get("e"));Record record = client.operate(null, key, MapOperation.getByKeyList("m", keys, MapReturnType.KEY_VALUE));// returns {a: 1, c: 3, e: 5}# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_get_by_key_list("m", ["a", "c", "e"], aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("a", 1), ("c", 3), ("e", 5)]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapGetByKeyListOp("m", []interface{}{"a", "c", "e"}, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{a: 1}, {c: 3}, {e: 5}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_arraylist keys;as_arraylist_init(&keys, 3, 0);as_arraylist_append_str(&keys, "a");as_arraylist_append_str(&keys, "c");as_arraylist_append_str(&keys, "e");
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_key_list(&ops, "m", NULL, (as_list*)&keys, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{a: 1}, {c: 3}, {e: 5}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
IList keys = new List<Value> { Value.Get("a"), Value.Get("c"), Value.Get("e")};Record record = client.Operate(null, key, MapOperation.GetByKeyList("m", keys, MapReturnType.KEY_VALUE));// returns {a: 1, c: 3, e: 5}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByKeyList('m', ['a', 'c', 'e'], maps.returnType.KEY_VALUE)])// result.bins.m == [{a: 1}, {c: 3}, {e: 5}]get_by_value_list(binName, values, returnType[, ctx])Get all {key: value} pairs where map.value ∈ valueList.
Multi result
Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
List<Value> values = Arrays.asList(Value.get(2), Value.get(4));Record record = client.operate(null, key, MapOperation.getByValueList("m", values, MapReturnType.KEY));// returns [b, d]# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_get_by_value_list("m", [2, 4], aerospike.MAP_RETURN_KEY)])# bins["m"] == ["b", "d"]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapGetByValueListOp("m", []any{2, 4}, as.MapReturnType.KEY),)// record.Bins["m"] == ["b", "d"]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_arraylist values;as_arraylist_init(&values, 2, 0);as_arraylist_append_int64(&values, 2);as_arraylist_append_int64(&values, 4);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_value_list(&ops, "m", NULL, (as_list*)&values, AS_MAP_RETURN_KEY);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == ["b", "d"]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
IList values = new List<Value> { Value.Get(2), Value.Get(4) };Record record = client.Operate(null, key, MapOperation.GetByValueList("m", values, MapReturnType.KEY));// returns [b, d]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByValueList('m', [2, 4], maps.returnType.KEY)])// result.bins.m == ['b', 'd']get_by_value(binName, value, returnType[, ctx])Get all {key: value} pairs where map.value == value.
Multi result
Requesting an INDEX return type adds 𝓞(N + M) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 1, d: 3}
Record record = client.operate(null, key, MapOperation.getByValue("m", Value.get(1), MapReturnType.KEY));// returns [a, c] (all keys with value == 1)# m = {a: 1, b: 2, c: 1, d: 3}
_, _, bins = client.operate(key, [ map_operations.map_get_by_value("m", 1, aerospike.MAP_RETURN_KEY)])# bins["m"] == ["a", "c"]// m = {a: 1, b: 2, c: 1, d: 3}
record, err := client.Operate(nil, key, as.MapGetByValueOp("m", 1, as.MapReturnType.KEY),)// record.Bins["m"] == ["a", "c"]// m = {a: 1, b: 2, c: 1, d: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_value(&ops, "m", NULL, (as_val*)as_integer_new(1), AS_MAP_RETURN_KEY);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == ["a", "c"]// m = {a: 1, b: 2, c: 1, d: 3}
Record record = client.Operate(null, key, MapOperation.GetByValue("m", Value.Get(1), MapReturnType.KEY));// returns [a, c]// m = {a: 1, b: 2, c: 1, d: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByValue('m', 1, maps.returnType.KEY)])// result.bins.m == ['a', 'c']get_by_index_range(binName, index[, count], returnType[, ctx])Get all {key: value} pairs where k = indexof(map.key) and k >= index and k < index + count. Omitting count select element(s) where k >= origin + index.
Multi result
Requesting a RANK return type adds 𝓞(N log N). Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
Record record = client.operate(null, key, MapOperation.getByIndexRange("m", 1, 2, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3} (2 entries starting at index 1)# m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
_, _, bins = client.operate(key, [ map_operations.map_get_by_index_range("m", 1, 2, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
record, err := client.Operate(nil, key, as.MapGetByIndexRangeCountOp("m", 1, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_index_range(&ops, "m", NULL, 1, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
Record record = client.Operate(null, key, MapOperation.GetByIndexRange("m", 1, 2, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByIndexRange('m', 1, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]get_by_index(binName, index, returnType[, ctx])Get {key: value} entry where map.key is the ith smallest key where i == index.
Single result
Requesting a RANK return type adds 𝓞(N), or 𝓞(log N) with a persisted full index. See Map performance.
// m = {a: 1, b: 2, c: 3} (K_ORDERED)
Record record = client.operate(null, key, MapOperation.getByIndex("m", 0, MapReturnType.KEY_VALUE));// returns {a: 1} (smallest key by index)
record = client.operate(null, key, MapOperation.getByIndex("m", -1, MapReturnType.KEY_VALUE));// returns {c: 3} (largest key by index)# m = {a: 1, b: 2, c: 3} (K_ORDERED)
_, _, bins = client.operate(key, [ map_operations.map_get_by_index("m", 0, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("a", 1)
_, _, bins = client.operate(key, [ map_operations.map_get_by_index("m", -1, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("c", 3)// m = {a: 1, b: 2, c: 3} (K_ORDERED)
record, err := client.Operate(nil, key, as.MapGetByIndexOp("m", 0, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {a: 1}
record, err = client.Operate(nil, key, as.MapGetByIndexOp("m", -1, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_index(&ops, "m", NULL, 0, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == {a: 1}
as_operations ops2;as_operations_inita(&ops2, 1);as_operations_map_get_by_index(&ops2, "m", NULL, -1, AS_MAP_RETURN_KEY_VALUE);
as_record* rec2 = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops2, &rec2);// rec2 bins "m" == {c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
Record record = client.Operate(null, key, MapOperation.GetByIndex("m", 0, MapReturnType.KEY_VALUE));// returns {a: 1}
record = client.Operate(null, key, MapOperation.GetByIndex("m", -1, MapReturnType.KEY_VALUE));// returns {c: 3}// m = {a: 1, b: 2, c: 3} (K_ORDERED)
const maps = Aerospike.maps
let result = await client.operate(key, [ maps.getByIndex('m', 0, maps.returnType.KEY_VALUE)])// result.bins.m == {a: 1}
result = await client.operate(key, [ maps.getByIndex('m', -1, maps.returnType.KEY_VALUE)])// result.bins.m == {c: 3}get_by_key_range(binName, keyBegin, keyEnd, returnType[, ctx])Get all {key: value} pairs where map.key >= keyStart and map.key < keyStop. Omitting keyStop select element(s) where map.key >= keyStart.
Multi result
Requesting a RANK return type adds 𝓞(N log N). Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.operate(null, key, MapOperation.getByKeyRange("m", Value.get("b"), Value.get("d"), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3} (keys >= "b" and < "d")# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_get_by_key_range("m", "b", "d", aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapGetByKeyRangeOp("m", "b", "d", as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_key_range(&ops, "m", NULL, (as_val*)as_string_new("b", false), (as_val*)as_string_new("d", false), AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.Operate(null, key, MapOperation.GetByKeyRange("m", Value.Get("b"), Value.Get("d"), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByKeyRange('m', 'b', 'd', maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]get_by_key_rel_index_range(binName, key, index[, count], returnType[, ctx])Get all {key: value} pairs where origin = index(key), k = indexof(map.key) and k >= origin + index and k < origin + index + count. Omitting count select element(s) where k >= origin + index.
Multi result
// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// Starting from key "b" (index 1), offset 0, count 3
Record record = client.operate(null, key, MapOperation.getByKeyRelativeIndexRange("m", Value.get("b"), 0, 3, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3, d: 4}# m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)# Starting from key "b" (index 1), offset 0, count 3
_, _, bins = client.operate(key, [ map_operations.map_get_by_key_index_range_relative("m", "b", 0, aerospike.MAP_RETURN_KEY_VALUE, count=3)])# bins["m"] == [("b", 2), ("c", 3), ("d", 4)]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// Starting from key "b" (index 1), offset 0, count 3
record, err := client.Operate(nil, key, as.MapGetByKeyRelativeIndexRangeCountOp("m", "b", 0, 3, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}, {d: 4}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// Starting from key "b" (index 1), offset 0, count 3
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_key_rel_index_range(&ops, "m", NULL, (as_val*)as_string_new("b", false), 0, 3, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}, {d: 4}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// Starting from key "b" (index 1), offset 0, count 3
Record record = client.Operate(null, key, MapOperation.GetByKeyRelativeIndexRange("m", Value.Get("b"), 0, 3, MapReturnType.KEY_VALUE));// returns {b: 2, c: 3, d: 4}// m = {a: 1, b: 2, c: 3, d: 4, e: 5} (K_ORDERED)// Starting from key "b" (index 1), offset 0, count 3
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByKeyRelIndexRange('m', 'b', 0, 3, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}, {d: 4}]get_by_key(binName, key, returnType[, ctx])Get entry {key: value} where map.key == key.
Single result
Requesting an INDEX return type adds 𝓞(N), or 𝓞(log N) with a persisted index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3}
Record record = client.operate(null, key, MapOperation.getByKey("m", Value.get("b"), MapReturnType.VALUE));// returns 2# m = {a: 1, b: 2, c: 3}
_, _, bins = client.operate(key, [ map_operations.map_get_by_key("m", "b", aerospike.MAP_RETURN_VALUE)])# bins["m"] == 2// m = {a: 1, b: 2, c: 3}
record, err := client.Operate(nil, key, as.MapGetByKeyOp("m", "b", as.MapReturnType.VALUE),)// record.Bins["m"] == 2// m = {a: 1, b: 2, c: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_key(&ops, "m", NULL, (as_val*)as_string_new("b", false), AS_MAP_RETURN_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == 2// m = {a: 1, b: 2, c: 3}
Record record = client.Operate(null, key, MapOperation.GetByKey("m", Value.Get("b"), MapReturnType.VALUE));// returns 2// m = {a: 1, b: 2, c: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByKey('m', 'b', maps.returnType.VALUE)])// result.bins.m == 2get_by_rank_range(binName, rank[, count], returnType[, ctx])Get all {key: value} pairs where r = rankof(map.value) and r >= rank and r < rank + count. Omitting count select element(s) where r >= rank.
Multi result
Requesting an INDEX return type adds 𝓞(N log N) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
Record record = client.operate(null, key, MapOperation.getByRankRange("m", 0, 2, MapReturnType.KEY_VALUE));// returns {b: 1, d: 2} (2 entries with lowest values)# m = {a: 3, b: 1, c: 5, d: 2, e: 4}
_, _, bins = client.operate(key, [ map_operations.map_get_by_rank_range("m", 0, 2, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 1), ("d", 2)]// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
record, err := client.Operate(nil, key, as.MapGetByRankRangeCountOp("m", 0, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 1}, {d: 2}]// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_rank_range(&ops, "m", NULL, 0, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 1}, {d: 2}]// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
Record record = client.Operate(null, key, MapOperation.GetByRankRange("m", 0, 2, MapReturnType.KEY_VALUE));// returns {b: 1, d: 2}// m = {a: 3, b: 1, c: 5, d: 2, e: 4}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByRankRange('m', 0, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 1}, {d: 2}]get_by_rank(binName, rank, returnType[, ctx])Get {key: value} entry where map.value is the ith smallest value where i == rank.
Single result
Requesting an INDEX return type adds 𝓞(N) on an unordered map, or 𝓞(1) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 3, b: 1, c: 2}
Record record = client.operate(null, key, MapOperation.getByRank("m", 0, MapReturnType.KEY_VALUE));// returns {b: 1} (smallest value)
record = client.operate(null, key, MapOperation.getByRank("m", -1, MapReturnType.KEY_VALUE));// returns {a: 3} (largest value)# m = {a: 3, b: 1, c: 2}
_, _, bins = client.operate(key, [ map_operations.map_get_by_rank("m", 0, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("b", 1)
_, _, bins = client.operate(key, [ map_operations.map_get_by_rank("m", -1, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == ("a", 3)// m = {a: 3, b: 1, c: 2}
record, err := client.Operate(nil, key, as.MapGetByRankOp("m", 0, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {b: 1}
record, err = client.Operate(nil, key, as.MapGetByRankOp("m", -1, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == {a: 3}// m = {a: 3, b: 1, c: 2}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_rank(&ops, "m", NULL, 0, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == {b: 1}
as_operations ops2;as_operations_inita(&ops2, 1);as_operations_map_get_by_rank(&ops2, "m", NULL, -1, AS_MAP_RETURN_KEY_VALUE);
as_record* rec2 = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops2, &rec2);// rec2 bins "m" == {a: 3}// m = {a: 3, b: 1, c: 2}
Record record = client.Operate(null, key, MapOperation.GetByRank("m", 0, MapReturnType.KEY_VALUE));// returns {b: 1}
record = client.Operate(null, key, MapOperation.GetByRank("m", -1, MapReturnType.KEY_VALUE));// returns {a: 3}// m = {a: 3, b: 1, c: 2}
const maps = Aerospike.maps
let result = await client.operate(key, [ maps.getByRank('m', 0, maps.returnType.KEY_VALUE)])// result.bins.m == {b: 1}
result = await client.operate(key, [ maps.getByRank('m', -1, maps.returnType.KEY_VALUE)])// result.bins.m == {a: 3}get_by_value_range(binName, valueBegin, valueEnd, returnType[, ctx])Get all {key: value} pairs where map.value >= valueStart and map.value < valueStop. Omitting valueStop select element(s) where map.value >= valueStart.
Multi result
Requesting an INDEX return type adds 𝓞(N + M) on an unordered map, or 𝓞(M) on a map with a persisted offset index. Requesting an ORDERED_MAP return type on an unordered map adds extra ordering cost relative to the number of elements in the result set. See Map performance.
// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.operate(null, key, MapOperation.getByValueRange("m", Value.get(2), Value.get(4), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3} (values >= 2 and < 4)# m = {a: 1, b: 2, c: 3, d: 4, e: 5}
_, _, bins = client.operate(key, [ map_operations.map_get_by_value_range("m", 2, 4, aerospike.MAP_RETURN_KEY_VALUE)])# bins["m"] == [("b", 2), ("c", 3)]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
record, err := client.Operate(nil, key, as.MapGetByValueRangeOp("m", 2, 4, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_value_range(&ops, "m", NULL, (as_val*)as_integer_new(2), (as_val*)as_integer_new(4), AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{b: 2}, {c: 3}]// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
Record record = client.Operate(null, key, MapOperation.GetByValueRange("m", Value.Get(2), Value.Get(4), MapReturnType.KEY_VALUE));// returns {b: 2, c: 3}// m = {a: 1, b: 2, c: 3, d: 4, e: 5}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByValueRange('m', 2, 4, maps.returnType.KEY_VALUE)])// result.bins.m == [{b: 2}, {c: 3}]get_by_value_rel_rank_range(binName, value, rank[, count], returnType[, ctx])Get all {key: value} pairs where origin = rank(value), r = rankof(map.value) and r >= origin + rank and r < origin + rank + count. Omitting count select element(s) where r >= origin + rank.
Multi result
// m = {a: 11, b: 22, c: 33, d: 44, e: 55}// Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
Record record = client.operate(null, key, MapOperation.getByValueRelativeRankRange("m", Value.get(30), 0, 2, MapReturnType.KEY_VALUE));// returns {c: 33, d: 44}# m = {a: 11, b: 22, c: 33, d: 44, e: 55}# Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
_, _, bins = client.operate(key, [ map_operations.map_get_by_value_rank_range_relative("m", 30, 0, aerospike.MAP_RETURN_KEY_VALUE, count=2)])# bins["m"] == [("c", 33), ("d", 44)]// m = {a: 11, b: 22, c: 33, d: 44, e: 55}// Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
record, err := client.Operate(nil, key, as.MapGetByValueRelativeRankRangeCountOp("m", 30, 0, 2, as.MapReturnType.KEY_VALUE),)// record.Bins["m"] == [{c: 33}, {d: 44}]// m = {a: 11, b: 22, c: 33, d: 44, e: 55}// Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_get_by_value_rel_rank_range(&ops, "m", NULL, (as_val*)as_integer_new(30), 0, 2, AS_MAP_RETURN_KEY_VALUE);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == [{c: 33}, {d: 44}]// m = {a: 11, b: 22, c: 33, d: 44, e: 55}// Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
Record record = client.Operate(null, key, MapOperation.GetByValueRelativeRankRange("m", Value.Get(30), 0, 2, MapReturnType.KEY_VALUE));// returns {c: 33, d: 44}// m = {a: 11, b: 22, c: 33, d: 44, e: 55}// Relative to value 30 (rank would be between b:22 and c:33), offset 0, count 2
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.getByValueRelRankRange('m', 30, 0, 2, maps.returnType.KEY_VALUE)])// result.bins.m == [{c: 33}, {d: 44}]size(binName[, ctx])Element count
// m = {a: 1, b: 2, c: 3}
Record record = client.operate(null, key, MapOperation.size("m"));// returns 3# m = {a: 1, b: 2, c: 3}
_, _, bins = client.operate(key, [ map_operations.map_size("m")])print(bins["m"])# 3// m = {a: 1, b: 2, c: 3}
record, err := client.Operate(nil, key, as.MapSizeOp("m"),)// record.Bins["m"] == 3// m = {a: 1, b: 2, c: 3}
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_size(&ops, "m", NULL);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// rec bins "m" == 3// m = {a: 1, b: 2, c: 3}
Record record = client.Operate(null, key, MapOperation.Size("m"));// returns 3// m = {a: 1, b: 2, c: 3}
const maps = Aerospike.maps
const result = await client.operate(key, [ maps.size('m')])// result.bins.m == 3Set operations
set_map_policy(mapPolicy, binName[, ctx])Modifies the order of an existing map. Order can be UNORDERED, K_ORDERED, or KV_ORDERED
null
The worst-case performance of modifying an unordered map to a K_ORDERED or KV_ORDERED one is 𝓞(N log N).
// m = {a: 1, b: 2, c: 3} (UNORDERED)
client.operate(null, key, MapOperation.setMapPolicy( new MapPolicy(MapOrder.KEY_ORDERED, MapWriteFlags.DEFAULT), "m"));// m is now K_ORDERED# m = {a: 1, b: 2, c: 3} (UNORDERED)
client.operate(key, [ map_operations.map_set_policy("m", { "map_order": aerospike.MAP_KEY_ORDERED })])# m is now K_ORDERED// m = {a: 1, b: 2, c: 3} (UNORDERED)
policy := as.NewMapPolicy(as.MapOrder.KEY_ORDERED, as.MapWriteMode.UPDATE)_, err := client.Operate(nil, key, as.MapSetPolicyOp(policy, "m"),)// m is now K_ORDERED// m = {a: 1, b: 2, c: 3} (UNORDERED)
as_map_policy mp;as_map_policy_set(&mp, AS_MAP_KEY_ORDERED, AS_MAP_WRITE_DEFAULT);
as_operations ops;as_operations_inita(&ops, 1);as_operations_map_set_policy(&ops, "m", NULL, &mp);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// m is now K_ORDERED// m = {a: 1, b: 2, c: 3} (UNORDERED)
client.Operate(null, key, MapOperation.SetMapPolicy( new MapPolicy(MapOrder.KEY_ORDERED, MapWriteFlags.DEFAULT), "m"));// m is now K_ORDERED// m = {a: 1, b: 2, c: 3} (UNORDERED)
const maps = Aerospike.maps
await client.operate(key, [ maps.setPolicy('m', new Aerospike.MapPolicy({ order: maps.order.KEY_ORDERED }))])// m is now K_ORDERED