Class: 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.


new RecordStream()

Source:
Example
const Aerospike = require('aerospike')
Aerospike.connect((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

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

Type:
  • boolean
Source:
See:

Methods


abort()

Aborts the query/scan operation.

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

Since:
  • v2.0
Source:

Events


data

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.

Source:

end

Source:

error

Type: AerospikeError
Source: