IndexJob

IndexJob

Potentially long-running index creation job.

Constructor

new IndexJob()

Source:
See:
Example
const Aerospike = require('aerospike')

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
  hosts: '192.168.33.10:3000',
  policies: {
    write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0})
  }
}

let binName = 'food'
let indexName = 'foodIndex'
let options = {
  ns: 'test',
  set: 'demo',
  bin: binName,
  index: indexName,
  datatype: Aerospike.indexDataType.STRING
}

Aerospike.connect(config)
  .then(client => {
    client.put(new Aerospike.Key('test', 'demo', 'mykey1'), {location: "Kale"})
    .then((result) => {
      client.createIndex(options)
      .then(job => job.wait())
      .then(() => {
        console.info('secondary index (SI) %s on %s was created successfully', indexName, binName)
        client.indexRemove('test', indexName)
        .then(() => {
          client.close()
        })
        .catch(error => {
          console.error('Error removing index:', error)
          client.close()
        })
      })
      .catch(error => {
        console.error('Error creating index:', error)
        client.close()
      })
    })
    .catch(error => {
        console.error('Error writing record:', error)
        client.close()
      })
  })
  .catch(error => console.error('Error connecting to cluster:',  error))

Extends

Methods

wait(pollIntervalopt, callbackopt) → (nullable) {Promise}

Wait until the job of creating a SI has completed.

Source:
Overrides:
Parameters:
Name Type Attributes Default Description
pollInterval number <optional>
1000

Interval in milliseconds to use when polling the cluster nodes.

callback doneCallback <optional>

The function to call when the operation completes.

Returns:

If no callback function is passed, the function returns a Promise that resolves once the job is completed.

Type
Promise