RecordStream

RecordStream

Stream of database records (full or partial) returned by Query or Scan operations.

Note: Record stream currently does not support Node.js' Stream#pause and Stream#resume methods, i.e. it always operates in flowing mode. That means data is read from the Aerospike database and provided to your application as fast as possible. If no data event handlers are attached, then data will be lost.

Aborting a Query/Scan

A query or scan operation can be aborted by calling the RecordStream#abort method at any time. It is no possible to continue a record stream, once aborted.

Constructor

new RecordStream()

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

// 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: {
    scan : new Aerospike.ScanPolicy({socketTimeout : 0, totalTimeout : 0}),
   }
}

Aerospike.connect(config, (error, client) => {
  if (error) throw error
  var recordsSeen = 0
  var scan = client.scan('test', 'demo')
  var stream = scan.foreach()

  stream.on('error', (error) => {
    console.error(error)
    throw error
  })
  stream.on('data', (record) => {
    recordsSeen++
    console.log(record)
    if (recordsSeen > 1000) {
      stream.abort() // We've seen enough!
    }
  })
  stream.on('end', () => {
    console.info(stream.aborted ? 'scan aborted' : 'scan completed')
    client.close()
  })
})

Extends

  • stream

Members

aborted :boolean

Description:
  • true if the scan has been aborted by the user; false otherwise.

Source:
See:

true if the scan has been aborted by the user; false otherwise.

Type:
  • boolean

Methods

abort()

Aborts the query/scan operation.

Once aborted, it is not possible to resume the stream.

Source:
Since:
  • v2.0

Events

data

Source:
Parameters:
Name Type Description
record Record

Aerospike record incl. bins, key and meta data. Depending on the operation, all, some or no bin values will be returned.

end

Source:

error

Source:
Type: