Function removeByIndex

  • Removes a single list element identified by its index from the list.

    Parameters

    • bin: string

      The name of the bin. The bin must contain a List value.

    • index: number

      Zero-based index of the item to remove.

    • OptionalreturnType: lists.returnType

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

    Returns ListOperation

    List operation that can be used with the Client#operate command.

    This operation returns the data specified by returnType.

    v3.4.0

    const Aerospike = require('aerospike')
    const lists = Aerospike.lists
    const key = new Aerospike.Key('test', 'demo', 'listsTest')
    // 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, { tags: ['blue', 'yellow', 'pink'] })
    const ops = [
    lists.removeByIndex('tags', 1)
    .andReturn(lists.returnType.VALUE)
    ]
    const result = await client.operate(key, ops)
    console.log('Result:', result.bins.tags) // => Result: yellow
    const record = await client.get(key)
    console.log('Record:', record.bins.tags) // => Record: [ 'blue', 'pink' ]
    client.close()
    })
MMNEPVFCICPMFPCPTTAAATR