Class Scan

since server 6.0

The scan object created by calling Client#scan is used for executing record scans on the specified namespace and set (optional). Scans can return a set of records as a RecordStream or apply an Aerospike UDF (user-defined function) on each of the records on the server.

Use query methods implemented by Client#query. For more information, please refer to the section on ⇑Historical evolution of scan features in the Aerospike technical documentation.

Using Scan#select it is possible to select a subset of bins which should be returned by the query. If no bins are selected, then the whole record will be returned. If the Scan#nobins property is set to true the only the record meta data (ttl, generation, etc.) will be returned.

A scan is executed using Scan#foreach. The method returns a RecordStream which emits a data event for each record returned by the scan. The scan can be aborted at any time by calling RecordStream#abort.

Record UDFs perform commands on a single record such as updating records based on a set of parameters. Using Scan#background you can run a Record UDF on the result set of a scan. Scans using Records UDFs are run in the background on the server and do not return the records to the client.

For additional information please refer to the section on ⇑Record UDFs in the Aerospike technical documentation.

Scan pagination allows for queries return records in pages rather than all at once. To enable scan pagination, the scan property Scan#paginate must be true and the previously stated scan policy ScanPolicy#maxRecords must be set to a nonzero positive integer in order to specify a maximum page size.

When a page is complete, RecordStream event 'error' will emit a Scan#scanState object containing a serialized version of the scan. This serialized scan, if be assigned back to Scan#scanState, allows the scan to retrieve the next page of records in the scan upon calling Scan#foreach. If 'error' emits an undefined object, either Scan#paginate is not true, or the scan has successfully returned all the specified records.

For additional information and examples, please refer to the Scan#paginate section below.

A client instance.

The namescape.

The name of a set.

Scan parameters.

List of bin names to select. See Scan#select.

Whether only meta data should be returned. See Scan#nobins.

Whether all cluster nodes should be scanned concurrently. See Scan#concurrent.

The time-to-live (expiration) of the record in seconds. See Scan#ttl.

Client#scan to create new instances of this class.

v2.0

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

const scan = client.scan('test', 'demo')
let recordsSeen = 0
const stream = scan.foreach()
stream.on('error', (error) => { throw error })
stream.on('end', () => client.close())
stream.on('data', (record) => {
console.log(record)
recordsSeen++
if (recordsSeen > 100) stream.abort() // We've seen enough!
})
})

Constructors

Properties

client: Client

Client instance.

concurrent?: boolean

If set to true, all cluster nodes will be scanned in parallel.

nobins?: boolean

If set to true, the scan will return only meta data, and exclude bins.

ns: string

Namespace to scan.

ops?: Operation[]
paginate?: boolean

If set to true, paginated queries are enabled. In order to receive paginated results, the ScanPolicy#maxRecords property must assign a nonzero integer value.

scanState?: number[]

If set to a valid serialized scan, calling Scan#foreach will allow the next page of records to be queried while preserving the progress of the previous scan. If set to null, calling Scan#foreach will begin a new scan.

selected?: string[]

List of bin names to be selected by the scan. If a scan specifies bins to be selected, then only those bins will be returned. If no bins are selected, then all bins will be returned (unless Scan#nobins is set to true).

Use Scan#select to specify the bins to select.

set: string

Name of the set to scan.

ttl?: number
udf?: UDF

Methods

  • Perform a read-write background scan and apply a Lua user-defined function (UDF) to each record.

    Parameters

    • udfModule: string

      UDF module name.

    • udfFunction: string

      UDF function name.

    • OptionaludfArgs: AerospikeBinValue[]

      Arguments for the function.

    • Optionalpolicy: policy.ScanPolicy

      The Scan Policy to use for this command.

    • OptionalscanID: number

      Job ID to use for the scan; will be assigned randomly if zero or undefined.

    Returns Promise<Job<JobInfoResponse>>

    A Promise that resolves to a Job instance.

    When a background scan is initiated, the client will not wait for results from the database. Instead a Job instance will be returned, which can be used to query the scan status on the database.

  • Parameters

    • udfModule: string

      UDF module name.

    • udfFunction: string

      UDF function name.

    • callback: TypedCallback<Job<JobInfoResponse>>

      The function to call when the command completes.

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    • udfModule: string

      UDF module name.

    • udfFunction: string

      UDF function name.

    • udfArgs: AerospikeBinValue[]

      Arguments for the function.

    • policy: policy.ScanPolicy

      The Scan Policy to use for this command.

    • scanID: number

      Job ID to use for the scan; will be assigned randomly if zero or undefined.

    • callback: TypedCallback<Job<JobInfoResponse>>

      The function to call when the command completes.

    Returns void

  • Performs a read-only scan on each node in the cluster. As the scan iterates through each partition, it returns the current version of each record to the client.

    Parameters

    • Optionalpolicy: null | policy.ScanPolicy

      The Scan Policy to use for this command.

    • OptionaldataCb: ((data: AerospikeRecord) => void)

      The function to call when the command completes with the results of the command; if no callback function is provided, the method returns a Promise instead.

    • OptionalerrorCb: ((error: Error) => void)

      Callback function called when there is an error.

        • (error): void
        • Parameters

          • error: Error

          Returns void

    • OptionalendCb: (() => void)

      Callback function called when an operation has completed.

        • (): void
        • Returns void

    Returns RecordStream

  • Checks compiliation status of a paginated scan.

    Returns boolean

    True if a next page exists, false otherwise

    If false is returned, there are no more records left in the scan, and the scan is complete. If true is returned, calling Scan#foreach will continue from the state specified by Scan#scanState.

  • Applies write operations to all matching records.

    Parameters

    • operations: Operation[]

      List of write operations to perform on the matching records.

    • Optionalpolicy: policy.ScanPolicy

      The Scan Policy to use for this command.

    • OptionalscanID: number

      Job ID to use for the scan; will be assigned randomly if zero or undefined.

    Returns Promise<Job<JobInfoResponse>>

    A Promise that resolves to a Job instance.

    Performs a background scan and applies one or more write operations to all records. Neither the records nor the results of the operations are returned to the client. Instead a Job instance will be returned, which can be used to query the scan status.

    This method requires server >= 3.7.0.

    v3.14.0

    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).then(async (client) => {
    const scan = client.scan('namespace', 'set')
    const ops = [Aerospike.operations.incr('count', 1)]
    const job = await scan.operate(ops)
    await job.waitUntilDone()
    client.close()
    })
  • Parameters

    • operations: Operation[]

      List of write operations to perform on the matching records.

    • policy: policy.ScanPolicy

      The Scan Policy to use for this command.

    • scanID: number

      Job ID to use for the scan; will be assigned randomly if zero or undefined.

    • callback: TypedCallback<Job<JobInfoResponse>>

      The function to call when the command completes.

    Returns void

  • Specify the begin and count of the partitions to be scanned by the scan foreach op.

    Parameters

    • begin: number

      Start partition number to scan.

    • count: number

      Number of partitions from the start to scan.

    • Optionaldigest: Buffer

      Start from this digest if it is specified.

    Returns any

    If a scan specifies partitions begin and count, then only those partitons will be scanned and returned. If no partitions are specified, then all partitions will be scanned and returned.

  • Specify the names of bins to be selected by the scan.

    Parameters

    • bins: string[]

      List of bin names to return.

    Returns void

    If a scan specifies bins to be selected, then only those bins will be returned. If no bins are selected, then all bins will be returned. (Unless Scan#nobins is set to true.)

  • Specify the names of bins to be selected by the scan.

    Parameters

    • Rest...bins: string[]

      Spread of bin names to return.

    Returns void

    If a scan specifies bins to be selected, then only those bins will be returned. If no bins are selected, then all bins will be returned. (Unless Scan#nobins is set to true.)

MMNEPVFCICPMFPCPTTAAATR