Function insert

  • Inserts an element at the specified index.

    Parameters

    • bin: string

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

    • index: number

      List index at which the new element should be inserted.

    • value: AerospikeBinValue

      The value to be appended.

    • Optionalpolicy: policy.ListPolicy

      Optional list policy.

    Returns ListOperation

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

    This operation returns the element count of the list after the operation.

    const Aerospike = require('aerospike')
    const op = Aerospike.operations
    const lists = Aerospike.lists
    const key = new Aerospike.Key('test', 'demo', 'mykey1')
    // 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})
    }
    }

    var ops = [
    lists.insert('tags', 2, 'orange'),
    op.read('tags')
    ]

    Aerospike.client(config).connect((error, client) => {
    if (error) throw error
    client.put(key, { tags: ['blue', 'yellow', 'pink'] }, (error) => {
    if (error) throw error
    client.operate(key, ops, (error, result) => {
    if (error) throw error
    console.log(result.bins.tags) // => [ 'blue', 'yellow', 'orange', 'pink' ]
    client.close()
    })
    })
    })
MMNEPVFCICPMFPCPTTAAATR