This module defines operations on the Sorted Map data type that
can be used with the Client#operate
command. Operations on Sorted
Maps require Aerospike Server
⇑version 3.8.4
or later.
For more information, please refer to the ⇑Maps documentation in the Aerospike Feature Guide.
Sorted Maps
The Map data type supports both unordered and ordered maps. Maps can be
ordered by key, or by key and value. By default, maps are unordered. The map
order is controlled through the map policy and can be set either when the
map is created through the put
or putItems
operations or later on through the
setPolicy
operation.
All maps maintain an index and a rank. The index is the item offset from the start of the map, for both unordered and ordered maps. The rank is the sorted index of the value component. Map supports negative indexing for index and rank.
Index examples:
- Index 0: First item in map.
- Index 4: Fifth item in map.
- Index -1: Last item in map.
- Index -3: Third to last item in map.
- Index 1 Count 2: Second and third items in map.
- Index -3 Count 3: Last three items in map.
- Index -5 Count 4: Range between fifth to last item to second to last item inclusive.
Rank examples:
- Rank 0: Item with lowest value rank in map.
- Rank 4: Fifth lowest ranked item in map.
- Rank -1: Item with highest ranked value in map.
- Rank -3: Item with third highest ranked value in map.
- Rank 1 Count 2: Second and third lowest ranked items in map.
- Rank -3 Count 3: Top three ranked items in map.
CDT Context - Operating on Nested Maps
To operate on nested maps, use the MapOperation#withContext
function to set the context for a map operation.
- Description:
This module defines operations on the Sorted Map data type that can be used with the
Client#operate
command. Operations on Sorted Maps require Aerospike Server ⇑version 3.8.4 or later.For more information, please refer to the ⇑Maps documentation in the Aerospike Feature Guide.
Sorted Maps
The Map data type supports both unordered and ordered maps. Maps can be ordered by key, or by key and value. By default, maps are unordered. The map order is controlled through the map policy and can be set either when the map is created through the
put
orputItems
operations or later on through thesetPolicy
operation.All maps maintain an index and a rank. The index is the item offset from the start of the map, for both unordered and ordered maps. The rank is the sorted index of the value component. Map supports negative indexing for index and rank.
Index examples:
- Index 0: First item in map.
- Index 4: Fifth item in map.
- Index -1: Last item in map.
- Index -3: Third to last item in map.
- Index 1 Count 2: Second and third items in map.
- Index -3 Count 3: Last three items in map.
- Index -5 Count 4: Range between fifth to last item to second to last item inclusive.
Rank examples:
- Rank 0: Item with lowest value rank in map.
- Rank 4: Fifth lowest ranked item in map.
- Rank -1: Item with highest ranked value in map.
- Rank -3: Item with third highest ranked value in map.
- Rank 1 Count 2: Second and third lowest ranked items in map.
- Rank -3 Count 3: Top three ranked items in map.
CDT Context - Operating on Nested Maps
To operate on nested maps, use the
MapOperation#withContext
function to set the context for a map operation.
- Source:
- See:
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
remove : new Aerospike.RemovePolicy({socketTimeout : 0, totalTimeout : 0}),
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config).then(async client => {
let ops = [
maps.put('map', 'e', 5, {
order: maps.order.KEY_ORDERED
}), // => { e: 5 }
maps.putItems('map', { d: 4, b: 2, c: 3 }), // => { b: 2, c: 3, d: 4, e: 5 }
maps.putItems('map', { c: 99, a: 1 }, {
writeFlags: maps.writeFlags.CREATE_ONLY
| maps.writeFlags.NO_FAIL
| maps.writeFlags.PARTIAL
}), // => { a: 1, b: 2, c: 3, d: 4, e: 5 }
maps.removeByValue('map', 3), // => { a: 1, b: 2, d: 4, e: 5 }
maps.removeByIndexRange('map', -2)
.andReturn(maps.returnType.KEY) // => { a: 1, b: 2 }
]
let result = await client.operate(key, ops)
console.log(result.bins.map) // => ['d', 'e']
let record = await client.get(key)
console.log(record.bins.map) // => { a: 1, b: 2 }
await client.remove(key)
client.close()
})
Classes
Members
(static) order :Object
Map order.
- Description:
The order determines what kind of index the Aerospike server maintains for the map.
- Source:
Properties:
Name | Type | Description |
---|---|---|
UNORDERED |
number | Map is not ordered. This is the default. |
KEY_ORDERED |
number | Order map by key. |
KEY_VALUE_ORDERED |
number | Order map by key, then value. |
The order determines what kind of index the Aerospike server maintains for the map.
Type:
- Object
(static) returnType :Object
Map return type.
- Description:
The return type determines what data of the selected items the get and remove operations return in the result of the
Client#operate
command. It is optional to specify the return type for remove operations; default isNONE
. For get operations the return type parameter is required.
- Source:
Properties:
Name | Type | Description |
---|---|---|
NONE |
number | Do not return a result; this is the default. |
INDEX |
number | Return key index order. (0 = first key, 1 = second key, ...) |
REVERSE_INDEX |
number | Return reverse key order. (0 = last key, -1 = second last key, ...) |
RANK |
number | Return value order. (0 = smallest value, 1 = second smallest value, ...) |
REVERSE_RANK |
number | Return reverse value order. (0 = largest value, -1 = second largest value, ...) |
COUNT |
number | Return count of items selected. |
KEY |
number | Return key for single key read and key list for range read. |
VALUE |
number | Return value for single key read and value list for range read. |
KEY_VALUE |
number | Return map items keys and values as an Array. i.e. [key1, value1, key2, value2, ...]. |
EXISTS |
number | Return true if count > 0. |
UNORDERED_MAP |
number | Return an unordered map. |
ORDERED_MAP |
number | Return an ordered map. |
The return type determines what data of the selected items the
get and remove operations return in the result of the Client#operate
command. It is optional to specify the return type for remove operations;
default is NONE
. For get operations the return type parameter
is required.
Type:
- Object
(static) writeFlags :Object
Map write flags.
- Description:
Write flags are used to determine the criteria for a successful operation.
Map write flags require server version v4.3 or later. For earier server versions, set the
writeMode
instead.
- Source:
- Since:
- v3.5.0
Properties:
Name | Type | Description |
---|---|---|
DEFAULT |
number | Allow create or update. Default. |
CREATE_ONLY |
number | If the key already exists, the item will be denied. If the key does not exist, a new item will be created. |
UPDATE_ONLY |
number | If the key already exists, the item will be overwritten. If the key does not exist, the item will be denied. |
NO_FAIL |
number | Do not raise error, if map item is denied due to write flag constraints. |
PARTIAL |
number | Allow other valid map items to be committed, if a map item is denied due to write flag constraints. |
Write flags are used to determine the criteria for a successful operation.
Map write flags require server version v4.3 or later. For earier server
versions, set the writeMode
instead.
Type:
- Object
(static) writeMode :Object
Map write mode.
- Description:
Write mode is used to determine the criteria for a successful operation.
Map write mode should only be used for server versions prior to v4.3. For server versions v4.3 or later, the use of
writeFlags
is recommended.
- Source:
- Deprecated:
- since v3.5.0
Properties:
Name | Type | Description |
---|---|---|
UPDATE |
number | If the key already exists, the item will be overwritten. If the key does not exist, a new item will be created. This is the default write mode. |
UPDATE_ONLY |
number | If the key already exists, the item will be overwritten. If the key does not exist, the write will fail. |
CREATE_ONLY |
number | If the key already exists, the write will fail. If the key does not exist, a new item will be created. |
Write mode is used to determine the criteria for a successful operation.
Map write mode should only be used for server versions prior to v4.3. For
server versions v4.3 or later, the use of writeFlags
is recommended.
Type:
- Object
Methods
(static) clear(bin) → {Object}
Removes all items in the map.
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. If the bin exists, it must contain a Map value; if it does not yet exist, a new Map may be created depending on the map policy's write mode. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) create(bin, order, count, ctx) → {Object}
Creates map create operation.
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config).then(async client => {
let ops = [
maps.create('map', maps.order.KEY_ORDERED, true)
]
let result = await client.operate(key, ops)
console.log(result.bins) // => { map: null }
let record = await client.get(key)
console.log(record.bins) // => { map: {} }
await client.remove(key)
client.close()
})
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | bin name. |
order |
number | map order. |
count |
persistIndex | if true, persist map index. A map index improves lookup performance, but requires more storage. A map index can be created for a top-level ordered map only. Nested and unordered map indexes are not supported. |
ctx |
number | optional path to nested map. If not defined, the top-level map is used. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) decrement(bin, key, decr, policyopt) → {Object}
Decrements the map entry identified by the given key by the value
decr
. Valid only for numeric values.
- Description:
If a map entry with the given key does not exist, the map policy's write mode determines whether a new entry will be created same as for the
put
command. This operation may create a new map if the map bin is currently empty.This operation returns the new value of the map entry.
- Source:
- Deprecated:
- since v4.0.0 - use increment function with negative value instead.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin. If the bin exists, it must contain a Map value; if it does not yet exist, a new Map may be created depending on the map policy's write mode. |
|
key |
any | The map key. |
|
decr |
number | The value to decrement the map entry by. |
|
policy |
MapPolicy |
<optional> |
The map policy. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByIndex(bin, index, returnTypeopt) → {Object}
Retrieves a single item identified by it's index value from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Index of the entry to remove. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByIndexRange(bin, index, countopt, returnTypeopt) → {Object}
Retrieves one or more items in the specified index range from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Starting index. |
|
count |
number |
<optional> |
Number of items to delete. If undefined, the range
includes all items starting from |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByKey(bin, key, returnTypeopt) → {Object}
Retrieves a single item identified by key from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
key |
any | The map key. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByKeyList(bin, keys, returnTypeopt) → {Object}
Retrieves map items identified by keys list.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
keys |
any | The map keys. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByKeyRange(bin, beginnullable, endnullable, returnTypeopt) → {Object}
Retrieves one or more items identified by a range of keys from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
begin |
any |
<nullable> |
Start key in the range (inclusive). If set to
|
end |
any |
<nullable> |
End key in the range (exclusive). If set to
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByKeyRelIndexRange(bin, key, index, countopt, returnTypeopt) → {Object}
Retrieves map items nearest to key and greater, by index, from the map.
- Description:
This operation returns the selected data specified by
returnType
.Examples for map { a: 17, e: 2, f: 15, j: 10 }:
- (value, index, count) = [selected items]
- ('f', 0, 1) = { f: 15 }
- ('f', 1, 2) = { j: 10 }
- ('f', -1, 1) = { e: 2 }
- ('b', 2, 1) = { j: 10 }
- ('b', -2, 2) = { a: 17 }
Without count:
- (value, index) = [selected items]
- ('f', 0) = { f: 15, j: 10 }
- ('f', 1) = { j: 10 }
- ('f', -1) = { e: 2, f: 15, j: 10 }
- ('b', 2) = { j: 10 }
- ('b', -2) = { a: 17, e: 2, f: 15, j: 10 }
Requires Aerospike Server v4.3.0 or later.
- Source:
- Since:
- v3.5.0
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config)
.then(async client => {
await client.put(key, { map: { a: 17, e: 2, f: 15, j: 10 } })
let result = await client.operate(key, [
maps.getByKeyRelIndexRange('map', 'b', 2, 1)
.andReturn(maps.returnType.KEY_VALUE)])
console.info(result.bins.map) // => [ 'j', 10 ]
client.close()
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
key |
any | Find map items nearest to this key and greater. |
|
index |
number | Index of items to be retrieved relative to the given key. |
|
count |
number |
<optional> |
Number of items to retrieve. If undefined, the range includes all items nearest to key and greater, until the end. |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByRank(bin, rank, returnTypeopt) → {Object}
Retrieves a single item identified by it's rank value from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
rank |
number | Rank of the entry to remove. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByRankRange(bin, index, count, returnTypeopt) → {Object}
Retrieves one or more items in the specified rank range from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Starting rank. |
|
count |
number | Number of items to delete; if not specified, the
range includes all items starting from |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByValue(bin, value, returnTypeopt) → {Object}
Retrieves one or more items identified by a single value from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
value |
any | The map value. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByValueList(bin, values, returnTypeopt) → {Object}
Retrieves map items identified by values from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
values |
any | The map values. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByValueRange(bin, beginnullable, endnullable, returnTypeopt) → {Object}
Retrieves one or more items identified by a range of values from the map.
- Description:
This operation returns the data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
begin |
any |
<nullable> |
Start values in the range (inclusive). If set to
|
end |
any |
<nullable> |
End value in the range (exclusive). If set to
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) getByValueRelRankRange(bin, value, rank, countopt, returnTypeopt) → {Object}
Retrieves map items nearest to value and greater, by relative rank.
- Description:
This operation returns the selected data specified by
returnType
.Examples for map { e: 2, j: 10, f: 15, a: 17 }:
- (value, rank, count) = [selected items]
- (11, 1, 1) = { a: 17 }
- (11, -1, 1) = { j: 10 }
Without count:
- (value, rank) = [selected items]
- (11, 1) = { a: 17 }
- (11, -1) = { j: 10, f: 15, a: 17 }
- Source:
- Since:
- v3.5.0
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config)
.then(async client => {
await client.put(key, { map: { e: 2, j: 10, f: 15, a: 17 } })
let result = await client.operate(key, [
maps.getByValueRelRankRange('map', 11, 1, 1)
.andReturn(maps.returnType.KEY_VALUE)])
console.info(result.bins.map) // => [ 'a', 17 ]
client.close()
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
value |
any | Find map items nearest to this value and greater. |
|
rank |
number | Rank of items to be retrieved relative to the given value. |
|
count |
number |
<optional> |
Number of items to retrieve. If undefined, the range includes all items nearest to value and greater, until the end. |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) increment(bin, key, incr, policyopt) → {Object}
Increments the map entry identified by the given key by the value
incr
. Valid only for numeric values.
- Description:
If a map entry with the given key does not exist, the map policy's write mode determines whether a new entry will be created same as for the
put
command. This operation may create a new map if the map bin is currently empty.This operation returns the new value of the map entry.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin. If the bin exists, it must contain a Map value; if it does not yet exist, a new Map may be created depending on the map policy's write mode. |
|
key |
any | The map key. |
|
incr |
number | The value to increment the map entry by. Use negative value to decrement map entry. |
|
policy |
MapPolicy |
<optional> |
The map policy. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) put(bin, key, value, policyopt) → {Object}
Writes a key/value item to the map.
- Description:
Depending on the map policy and whether an entry with the same key already exists in the map, a new key will be added to the map or the existing entry with the same key will be updated. If the bin does not yet contain a map value, a new map may be created.
This operation returns the new size of the map.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin. If the bin exists, it must contain a Map value; if it does not yet exist, a new Map may be created depending on the map policy's write mode. |
|
key |
any | Map key to write. |
|
value |
any | Map value to write. |
|
policy |
MapPolicy |
<optional> |
The map policy. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) putItems(bin, items, policyopt) → {Object}
Writes each entry of the given map to the map bin on the server.
- Description:
For each item, depending on the map policy and whether an entry with the same key already exists in the map, a new entry will be added to the map or the existing entry with the same key will be updated. If the bin does not yet contain a map value, a new map may be created.
This operation returns the new size of the map.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin. If the bin exists, it must contain a Map value; if it does not yet exist, a new Map may be created depending on the map policy's write mode. |
|
items |
object | One or more key value pairs to write to the map. |
|
policy |
MapPolicy |
<optional> |
The map policy. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByIndex(bin, index, returnTypeopt) → {Object}
Removes a single item identified by its index value from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Index of the entry to remove. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByIndexRange(bin, index, countopt, returnTypeopt) → {Object}
Removes one or more items in the specified index range from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Starting index. |
|
count |
number |
<optional> |
Number of items to delete. If undefined, the range
includes all items starting from |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByKey(bin, key, returnTypeopt) → {Object}
Removes a single item identified by key from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
key |
any | The map key. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByKeyList(bin, keys, returnTypeopt) → {Object}
Removes one or more items identified by key from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
keys |
Array.<any> | An array of map keys. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByKeyRange(bin, beginnullable, endnullable, returnTypeopt) → {Object}
Removes one or more items identified by a range of keys from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
begin |
any |
<nullable> |
Start key in the range (inclusive). If set to
|
end |
any |
<nullable> |
End key in the range (exclusive). If set to
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByKeyRelIndexRange(bin, key, index, countopt, returnTypeopt) → {Object}
Removes map items nearest to key and greater, by index, from the map.
- Description:
This operation returns the removed data specified by
returnType
.Examples for map { a: 17, e: 2, f: 15, j: 10 }:
- (value, index, count) = [removed items]
- ('f', 0, 1) = { f: 15 }
- ('f', 1, 2) = { j: 10 }
- ('f', -1, 1) = { e: 2 }
- ('b', 2, 1) = { j: 10 }
- ('b', -2, 2) = { a: 17 }
Without count:
- (value, index) = [removed items]
- ('f', 0) = { f: 15, j: 10 }
- ('f', 1) = { j: 10 }
- ('f', -1) = { e: 2, f: 15, j: 10 }
- ('b', 2) = { j: 10 }
- ('b', -2) = { a: 17, e: 2, f: 15, j: 10 }
Requires Aerospike Server v4.3.0 or later.
- Source:
- Since:
- v3.5.0
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config)
.then(async client => {
await client.put(key, { map: { a: 17, e: 2, f: 15, j: 10 } })
let result = await client.operate(key, [
maps.removeByKeyRelIndexRange('map', 'f', -1, 1)
.andReturn(maps.returnType.KEY_VALUE)])
console.info(result.bins.map) // => [ 'e', 2 ]
let record = await client.get(key)
console.info(record.bins.map) // => { a: 17, f: 15, j: 10 }
client.close()
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
key |
any | Find map items nearest to this key and greater. |
|
index |
number | Index of items to be removed relative to the given key. |
|
count |
number |
<optional> |
Number of items to remove. If undefined, the range includes all items nearest to key and greater, until the end. |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByRank(bin, rank, returnTypeopt) → {Object}
Removes a single item identified by its rank value from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
rank |
number | Rank of the item to remove. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByRankRange(bin, index, countopt, returnTypeopt) → {Object}
Removes one or more items in the specified rank range from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
index |
number | Starting rank. |
|
count |
number |
<optional> |
Number of items to delete. If undefined, the range
includes all items starting from |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByValue(bin, value, returnTypeopt) → {Object}
Removes one or more items identified by a single value from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
value |
any | The map value. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByValueList(bin, values, returnTypeopt) → {Object}
Removes one or more items identified by a list of values from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
values |
Array.<any> | An array of map values. |
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByValueRange(bin, beginnullable, endnullable, returnTypeopt) → {Object}
Removes one or more items identified by a range of values from the map.
- Description:
This operation returns the removed data specified by
returnType
.
- Source:
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
begin |
any |
<nullable> |
Start values in the range (inclusive). If set to
|
end |
any |
<nullable> |
End value in the range (exclusive). If set to
|
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) removeByValueRelRankRange(bin, value, rank, countopt, returnTypeopt) → {Object}
Removes map items nearest to value and greater, by relative rank.
- Description:
This operation returns the removed data specified by
returnType
.Examples for map { e: 2, j: 10, f: 15, a: 17 }:
- (value, rank, count) = [removed items]
- (11, 1, 1) = { a: 17 }
- (11, -1, 1) = { j: 10 }
Without count:
- (value, rank) = [removed items]
- (11, 1) = { a: 17 }
- (11, -1) = { j: 10, f: 15, a: 17 }
- Source:
- Since:
- v3.5.0
- See:
-
- Instead of passing
returnType
, you can also useMapOperation#andReturn
to select what data to return.
- Instead of passing
Example
const Aerospike = require('aerospike')
const maps = Aerospike.maps
const key = new Aerospike.Key('test', 'demo', 'mapKey')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
Aerospike.connect(config)
.then(async client => {
await client.put(key, { map: { e: 2, j: 10, f: 15, a: 17 } })
let result = await client.operate(key, [
maps.removeByValueRelRankRange('map', 11, -1)
.andReturn(maps.returnType.KEY_VALUE)])
console.info(result.bins.map) // => [ 'j', 10, 'f', 15, 'a', 17 ]
let record = await client.get(key)
console.info(record.bins.map) // => { e: 2 }
client.close()
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
|
value |
any | Find map items nearest to this value and greater. |
|
rank |
number | Rank of items to be removed relative to the given value. |
|
count |
number |
<optional> |
Number of items to remove. If undefined, the range includes all items nearest to value and greater, until the end. |
returnType |
number |
<optional> |
The |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) setPolicy(bin, policy) → {Object}
Sets map policy attributes.
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. The bin must contain a Map value. |
policy |
MapPolicy | The map policy. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object
(static) size(bin) → {Object}
Returns the size of the map.
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin, which must contain a Map value. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Object