All Products
Search
Document Center

Tablestore:Batch read data

Last Updated:Jun 22, 2026

The `batchGetRow` method in the Node.js SDK reads multiple rows from one or more Tablestore tables in a single request.

Notes

A single batch read operation can read up to 100 rows.

Prerequisites

Initialize a Tablestore client

Method

batchGetRow: function batchGetRow(params, callback)

Description of the `params` parameter

  • tables (required) (Array): The batch read information, which includes the following subparameters.

    Name

    Type

    Description

    tableName (required)

    string

    The name of the data table.

    primaryKey (required)

    Array

    Primary key information, including the primary key column names and values.

    • Supported primary key column data types are STRING, INTEGER, and BINARY.

    • The number and type of primary keys must match those defined in the data table.

    maxVersions (optional)

    number

    The maximum number of versions to return. Defaults to 1.

    • If more data versions match the query conditions than this value allows, Tablestore returns versions in descending order by timestamp (newest first).

    timeRange (optional)

    object

    The range of data versions to return.

    • Each attribute column in a Tablestore data table can have multiple versions. When you specify a version range, only data within that range is returned.

    columnsToGet (optional)

    Array

    The primary key columns or attribute columns to read.

    • If columnsToGet is not set, the entire row is returned.

    • If columnsToGet is set and none of the specified columns exist in the row, null is returned.

    columnFilter (optional)

    TableStore.ColumnCondition

    The filter condition. For more information, see Filters.

    • If both columnsToGet and columnFilter are set, Tablestore first returns the specified columns and then applies columnFilter to the results.

Examples

The following example reads two rows whose primary key values are row1 and row2 from the test_table table.

var table = {
    // Set the table name
    tableName: 'test_table',
    primaryKey: [
        // Add primary key information for row 1
        [{ 'id': 'row1' }],
        // Add primary key information for row 2
        [{ 'id': 'row2' }]
    ]
};
var params = {
    tables: [
        table
    ]
}

// Call the batchGetRow method to perform a batch data query
client.batchGetRow(params, function (err, data) {
    if (err) {
        console.log('Batch get row failed with error: ', err);
        return;
    }

    // Process the response
    console.log('* RequestId: ', data.RequestId);
    console.log('* Rows Data: ');
    data.tables.forEach(function (rows) {
        rows.forEach(function (row) {
            if (row.isOk) {
                console.log('Succeeded Row:', row.tableName, JSON.stringify(row.primaryKey), JSON.stringify(row.attributes));
            } else {
                console.log('Failed Row:', row.tableName, row.errorMessage);
            }
        });
    });
});

The following examples show how to set common parameters for batch reads.

  • Read data from multiple tables. You can include multiple tables in a single batch read request with separate query conditions for each table.

    var table1 = {
        tableName: 'orders_small',
        primaryKey: [
            [{ 'order_id': '90fb478c-1360-11f0-a34d-00163e30a2a9' }]
        ]
    };
    
    var params = {
        tables: [
            table,
            table1
        ]
    };
  • Set a data version range. Only data within the specified range is returned.

    // Set the version range to the past 24 hours from the current time
    table.timeRange = {
        startTime: (Date.now() - 86400 * 1000).toString(),
        endTime: Date.now().toString()
    }
  • Specify attribute columns to read.

    table.columnsToGet = ['col2']

References

Range read data