---
title: "Map operations"
description: "Learn to read, update, and remove elements in Aerospike map-type bins using server-side map operations."
---

# Map operations

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

Map operations read, update, and remove elements in map-type bins directly on the server.

Each operation is governed by a [map policy](#map-policy) (order, write flags, `PERSIST_INDEX`), can target nested elements using a [context](#context), and returns results controlled by a [return type](#return-types).

## 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](https://aerospike.com/docs/develop/data-types/collections/map#element-ordering). 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](#persisting-the-map-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](#persisting-the-map-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()`](https://aerospike.com/docs/develop/data-types/collections/map/operations#set_type) to convert between order types. See [Map performance](https://aerospike.com/docs/develop/data-types/collections/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](https://aerospike.com/docs/develop/data-types/collections/map/performance)).

### 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](https://aerospike.com/docs/develop/data-types/collections/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`](https://aerospike.com/docs/develop/data-types/collections/map/operations#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`

```python
clear(binName[, ctx])
```

Description: Clears the map. Map type stays the same.

Returns: null

Code sample: -   [Java](#tab-panel-1816)
-   [Python](#tab-panel-1817)
-   [Go](#tab-panel-1818)
-   [C](#tab-panel-1819)
-   [C#](#tab-panel-1820)
-   [Node.js](#tab-panel-1821)

```java
// m = {a: 1, b: 2, c: 3}

client.operate(null, key,

    MapOperation.clear("m")

);

// m == {}
```

```python
# m = {a: 1, b: 2, c: 3}

client.operate(key, [

    map_operations.map_clear("m")

])

# m == {}
```

```go
// m = {a: 1, b: 2, c: 3}

_, err := client.Operate(nil, key,

    as.MapClearOp("m"),

)

// m == {}
```

```c
// 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 == {}
```

```csharp
// m = {a: 1, b: 2, c: 3}

client.Operate(null, key,

    MapOperation.Clear("m")

);

// m == {}
```

```javascript
// m = {a: 1, b: 2, c: 3}

const maps = Aerospike.maps

await client.operate(key, [

    maps.clear('m')

])

// m == {}
```

---

#### `decrement`

```python
decrement(mapPolicy, binName, key, delta[, ctx])
```

Description: 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 |

Returns: New value after decrement

Code sample: -   [Java](#tab-panel-1822)
-   [Python](#tab-panel-1823)
-   [Go](#tab-panel-1824)
-   [C](#tab-panel-1825)
-   [C#](#tab-panel-1826)
-   [Node.js](#tab-panel-1827)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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")
```

```csharp
// 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}
```

```javascript
// 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`

```python
increment(mapPolicy, binName, key, delta[, ctx])
```

Description: 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 |

Returns: New value after increment

Code sample: -   [Java](#tab-panel-1828)
-   [Python](#tab-panel-1829)
-   [Go](#tab-panel-1830)
-   [C](#tab-panel-1831)
-   [C#](#tab-panel-1832)
-   [Node.js](#tab-panel-1833)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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")
```

```csharp
// 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}
```

```javascript
// 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`

```python
put_items(mapPolicy, binName, items[, ctx])
```

Description: 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.

Returns: The element count of the map after the operation, in the ‘bins’ part of the record under the _bin_ name.

Order: 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.

A note on write flags

Write flags can be combined to alter the behavior of the operation. For example, `CREATE_ONLY | NO_FAIL` will fail gracefully without throwing an exception if an element with the same map key already exists.

Using `DO_PARTIAL` will ensure that any element not violating the policy is added, even on a failed operation.

Code sample: -   [Java](#tab-panel-1834)
-   [Python](#tab-panel-1835)
-   [Go](#tab-panel-1836)
-   [C](#tab-panel-1837)
-   [C#](#tab-panel-1838)
-   [Node.js](#tab-panel-1839)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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)
```

```csharp
// 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}
```

```javascript
// 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`

```python
put(mapPolicy, binName, key, value[, ctx])
```

Description: Creates a map bin with a specified order, if the bin does not exist. Adds a key/value element to the map.

Returns: The element count of the map after the operation, in the ‘bins’ part of the record under the _bin_ name.

Order: 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.

A note on write flags

Write flags can be combined to alter the behavior of the operation. For example, `CREATE_ONLY | NO_FAIL` will fail gracefully without throwing an exception if an element with the same map key already exists.

`DO_PARTIAL` is not applicable for this operation.

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1840)
-   [Python](#tab-panel-1841)
-   [Go](#tab-panel-1842)
-   [C](#tab-panel-1843)
-   [C#](#tab-panel-1844)
-   [Node.js](#tab-panel-1845)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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)
```

```csharp
// 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}
```

```javascript
// 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_all_by_key_list`

```python
remove_by_key_list(binName, keys, returnType[, ctx])
```

Description: Remove all `{key: value}` pairs where `map.key ∈ keyList`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1846)
-   [Python](#tab-panel-1847)
-   [Go](#tab-panel-1848)
-   [C](#tab-panel-1849)
-   [C#](#tab-panel-1850)
-   [Node.js](#tab-panel-1851)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_all_by_value_list`

```python
remove_by_value_list(binName, values, returnType[, ctx])
```

Description: Remove all `{key: value}` pairs where `map.value ∈ valueList`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1852)
-   [Python](#tab-panel-1853)
-   [Go](#tab-panel-1854)
-   [C](#tab-panel-1855)
-   [C#](#tab-panel-1856)
-   [Node.js](#tab-panel-1857)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_all_by_value`

```python
remove_by_value(binName, value, returnType[, ctx])
```

Description: Remove all `{key: value}` pairs where `map.value == value`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1858)
-   [Python](#tab-panel-1859)
-   [Go](#tab-panel-1860)
-   [C](#tab-panel-1861)
-   [C#](#tab-panel-1862)
-   [Node.js](#tab-panel-1863)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_index_range(binName, index[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1864)
-   [Python](#tab-panel-1865)
-   [Go](#tab-panel-1866)
-   [C](#tab-panel-1867)
-   [C#](#tab-panel-1868)
-   [Node.js](#tab-panel-1869)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_index(binName, index, returnType[, ctx])
```

Description: Remove `{key: value}` entry where `map.key` is the ith smallest key where `i == index`.

Returns: Single result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1870)
-   [Python](#tab-panel-1871)
-   [Go](#tab-panel-1872)
-   [C](#tab-panel-1873)
-   [C#](#tab-panel-1874)
-   [Node.js](#tab-panel-1875)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_interval`

```python
remove_by_key_range(binName, keyBegin, keyEnd, returnType[, ctx])
```

Description: Remove all `{key: value}` pairs where `map.key >= keyStart` and `map.key < keyStop`. Omitting `keyStop` select element(s) where `map.key >= keyStart`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1876)
-   [Python](#tab-panel-1877)
-   [Go](#tab-panel-1878)
-   [C](#tab-panel-1879)
-   [C#](#tab-panel-1880)
-   [Node.js](#tab-panel-1881)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_key_rel_index_range(binName, key, index[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Code sample: -   [Java](#tab-panel-1882)
-   [Python](#tab-panel-1883)
-   [Go](#tab-panel-1884)
-   [C](#tab-panel-1885)
-   [C#](#tab-panel-1886)
-   [Node.js](#tab-panel-1887)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_key(binName, key, returnType[, ctx])
```

Description: Remove entry `{key: value}` where `map.key == key`.

Returns: Single result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1888)
-   [Python](#tab-panel-1889)
-   [Go](#tab-panel-1890)
-   [C](#tab-panel-1891)
-   [C#](#tab-panel-1892)
-   [Node.js](#tab-panel-1893)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_rank_range(binName, rank[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1894)
-   [Python](#tab-panel-1895)
-   [Go](#tab-panel-1896)
-   [C](#tab-panel-1897)
-   [C#](#tab-panel-1898)
-   [Node.js](#tab-panel-1899)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_rank(binName, rank, returnType[, ctx])
```

Description: Remove `{key: value}` entry where `map.value` is the ith smallest value where `i == rank`.

Returns: Single result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1900)
-   [Python](#tab-panel-1901)
-   [Go](#tab-panel-1902)
-   [C](#tab-panel-1903)
-   [C#](#tab-panel-1904)
-   [Node.js](#tab-panel-1905)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_interval`

```python
remove_by_value_range(binName, valueBegin, valueEnd, returnType[, ctx])
```

Description: Remove all `{key: value}` pairs where `map.value >= valueStart` and `map.value < valueStop`. Omitting `valueStop` select element(s) where `map.value >= valueStart`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1906)
-   [Python](#tab-panel-1907)
-   [Go](#tab-panel-1908)
-   [C](#tab-panel-1909)
-   [C#](#tab-panel-1910)
-   [Node.js](#tab-panel-1911)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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`

```python
remove_by_value_rel_rank_range(binName, value, rank[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Code sample: -   [Java](#tab-panel-1912)
-   [Python](#tab-panel-1913)
-   [Go](#tab-panel-1914)
-   [C](#tab-panel-1915)
-   [C#](#tab-panel-1916)
-   [Node.js](#tab-panel-1917)

```java
// 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}
```

```python
# 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}
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_all_by_key_list`

```python
get_by_key_list(binName, keys, returnType[, ctx])
```

Description: Get all `{key: value}` pairs where `map.key ∈ keyList`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1918)
-   [Python](#tab-panel-1919)
-   [Go](#tab-panel-1920)
-   [C](#tab-panel-1921)
-   [C#](#tab-panel-1922)
-   [Node.js](#tab-panel-1923)

```java
// 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}
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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_all_by_value_list`

```python
get_by_value_list(binName, values, returnType[, ctx])
```

Description: Get all `{key: value}` pairs where `map.value ∈ valueList`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1924)
-   [Python](#tab-panel-1925)
-   [Go](#tab-panel-1926)
-   [C](#tab-panel-1927)
-   [C#](#tab-panel-1928)
-   [Node.js](#tab-panel-1929)

```java
// 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]
```

```python
# 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"]
```

```go
// 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"]
```

```c
// 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"]
```

```csharp
// 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]
```

```javascript
// 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_all_by_value`

```python
get_by_value(binName, value, returnType[, ctx])
```

Description: Get all `{key: value}` pairs where `map.value == value`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1930)
-   [Python](#tab-panel-1931)
-   [Go](#tab-panel-1932)
-   [C](#tab-panel-1933)
-   [C#](#tab-panel-1934)
-   [Node.js](#tab-panel-1935)

```java
// 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)
```

```python
# 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"]
```

```go
// 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"]
```

```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"]
```

```csharp
// 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]
```

```javascript
// 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`

```python
get_by_index_range(binName, index[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1936)
-   [Python](#tab-panel-1937)
-   [Go](#tab-panel-1938)
-   [C](#tab-panel-1939)
-   [C#](#tab-panel-1940)
-   [Node.js](#tab-panel-1941)

```java
// 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)
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
get_by_index(binName, index, returnType[, ctx])
```

Description: Get `{key: value}` entry where `map.key` is the ith smallest key where `i == index`.

Returns: Single result

Performance: Requesting a `RANK` return type adds 𝓞(N), or 𝓞(log N) with a persisted full index. See [Map performance](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1942)
-   [Python](#tab-panel-1943)
-   [Go](#tab-panel-1944)
-   [C](#tab-panel-1945)
-   [C#](#tab-panel-1946)
-   [Node.js](#tab-panel-1947)

```java
// 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)
```

```python
# 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)
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_interval`

```python
get_by_key_range(binName, keyBegin, keyEnd, returnType[, ctx])
```

Description: Get all `{key: value}` pairs where `map.key >= keyStart` and `map.key < keyStop`. Omitting `keyStop` select element(s) where `map.key >= keyStart`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1948)
-   [Python](#tab-panel-1949)
-   [Go](#tab-panel-1950)
-   [C](#tab-panel-1951)
-   [C#](#tab-panel-1952)
-   [Node.js](#tab-panel-1953)

```java
// 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")
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
get_by_key_rel_index_range(binName, key, index[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Code sample: -   [Java](#tab-panel-1954)
-   [Python](#tab-panel-1955)
-   [Go](#tab-panel-1956)
-   [C](#tab-panel-1957)
-   [C#](#tab-panel-1958)
-   [Node.js](#tab-panel-1959)

```java
// 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}
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
get_by_key(binName, key, returnType[, ctx])
```

Description: Get entry `{key: value}` where `map.key == key`.

Returns: Single result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1960)
-   [Python](#tab-panel-1961)
-   [Go](#tab-panel-1962)
-   [C](#tab-panel-1963)
-   [C#](#tab-panel-1964)
-   [Node.js](#tab-panel-1965)

```java
// m = {a: 1, b: 2, c: 3}

Record record = client.operate(null, key,

    MapOperation.getByKey("m", Value.get("b"), MapReturnType.VALUE)

);

// returns 2
```

```python
# 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
```

```go
// m = {a: 1, b: 2, c: 3}

record, err := client.Operate(nil, key,

    as.MapGetByKeyOp("m", "b", as.MapReturnType.VALUE),

)

// record.Bins["m"] == 2
```

```c
// 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
```

```csharp
// m = {a: 1, b: 2, c: 3}

Record record = client.Operate(null, key,

    MapOperation.GetByKey("m", Value.Get("b"), MapReturnType.VALUE)

);

// returns 2
```

```javascript
// 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 == 2
```

---

#### `get_by_rank_range`

```python
get_by_rank_range(binName, rank[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1966)
-   [Python](#tab-panel-1967)
-   [Go](#tab-panel-1968)
-   [C](#tab-panel-1969)
-   [C#](#tab-panel-1970)
-   [Node.js](#tab-panel-1971)

```java
// 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)
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
get_by_rank(binName, rank, returnType[, ctx])
```

Description: Get `{key: value}` entry where `map.value` is the ith smallest value where `i == rank`.

Returns: Single result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1972)
-   [Python](#tab-panel-1973)
-   [Go](#tab-panel-1974)
-   [C](#tab-panel-1975)
-   [C#](#tab-panel-1976)
-   [Node.js](#tab-panel-1977)

```java
// 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)
```

```python
# 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)
```

```go
// 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}
```

```c
// 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}
```

```csharp
// 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}
```

```javascript
// 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_interval`

```python
get_by_value_range(binName, valueBegin, valueEnd, returnType[, ctx])
```

Description: Get all `{key: value}` pairs where `map.value >= valueStart` and `map.value < valueStop`. Omitting `valueStop` select element(s) where `map.value >= valueStart`.

Returns: Multi result

Performance: 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](https://aerospike.com/docs/develop/data-types/collections/map/performance).

Code sample: -   [Java](#tab-panel-1978)
-   [Python](#tab-panel-1979)
-   [Go](#tab-panel-1980)
-   [C](#tab-panel-1981)
-   [C#](#tab-panel-1982)
-   [Node.js](#tab-panel-1983)

```java
// 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)
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
get_by_value_rel_rank_range(binName, value, rank[, count], returnType[, ctx])
```

Description: 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`.

Returns: Multi result

Code sample: -   [Java](#tab-panel-1984)
-   [Python](#tab-panel-1985)
-   [Go](#tab-panel-1986)
-   [C](#tab-panel-1987)
-   [C#](#tab-panel-1988)
-   [Node.js](#tab-panel-1989)

```java
// 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}
```

```python
# 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)]
```

```go
// 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}]
```

```c
// 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}]
```

```csharp
// 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}
```

```javascript
// 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`

```python
size(binName[, ctx])
```

Returns: Element count

Code sample: -   [Java](#tab-panel-1990)
-   [Python](#tab-panel-1991)
-   [Go](#tab-panel-1992)
-   [C](#tab-panel-1993)
-   [C#](#tab-panel-1994)
-   [Node.js](#tab-panel-1995)

```java
// m = {a: 1, b: 2, c: 3}

Record record = client.operate(null, key,

    MapOperation.size("m")

);

// returns 3
```

```python
# m = {a: 1, b: 2, c: 3}

_, _, bins = client.operate(key, [

    map_operations.map_size("m")

])

print(bins["m"])

# 3
```

```go
// m = {a: 1, b: 2, c: 3}

record, err := client.Operate(nil, key,

    as.MapSizeOp("m"),

)

// record.Bins["m"] == 3
```

```c
// 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
```

```csharp
// m = {a: 1, b: 2, c: 3}

Record record = client.Operate(null, key,

    MapOperation.Size("m")

);

// returns 3
```

```javascript
// m = {a: 1, b: 2, c: 3}

const maps = Aerospike.maps

const result = await client.operate(key, [

    maps.size('m')

])

// result.bins.m == 3
```

---

## Set operations

#### `set_type`

```python
set_map_policy(mapPolicy, binName[, ctx])
```

Description: Modifies the order of an existing map. Order can be `UNORDERED`, `K_ORDERED`, or `KV_ORDERED`

Returns: null

Performance: The worst-case performance of modifying an unordered map to a `K_ORDERED` or `KV_ORDERED` one is 𝓞(N log N).

Code sample: -   [Java](#tab-panel-1996)
-   [Python](#tab-panel-1997)
-   [Go](#tab-panel-1998)
-   [C](#tab-panel-1999)
-   [C#](#tab-panel-2000)
-   [Node.js](#tab-panel-2001)

```java
// 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
```

```python
# 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
```

```go
// 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
```

```c
// 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
```

```csharp
// 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
```

```javascript
// 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
```

---