Function removeByKeyRelIndexRange

  • Removes map items nearest to key and greater, by index, from the map.

    Parameters

    • bin: string

      The name of the bin, which must contain a Map value.

    • key: string

      Find map items nearest to this key and greater.

    • index: number

      Index of items to be removed relative to the given key.

    • Optionalcount: number

      Number of items to remove. If undefined, the range includes all items nearest to key and greater, until the end.

    • OptionalreturnType: maps.returnType

      The return type indicating what data of the affected item(s) to return (if any).

    Returns MapOperation

    Operation that can be passed to the Client#operate command.

    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.

    Instead of passing returnType, you can also use ~MapOperation#andReturn|MapOperation#andReturn to select what data to return.

    v3.5.0

    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()
    })
MMNEPVFCICPMFPCPTTAAATR