All Products
Search
Document Center

Tablestore:Batch read data

Last Updated:Mar 12, 2026

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

Notes

A single batch read operation supports reading up to 100 rows of data.

Prerequisites

Initialize a Tablestore client

Method

batchGetRow: function batchGetRow(params, callback)

Description of the `params` parameter

  • tables (required) (Array): This parameter specifies the information for batch reading data. It 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. Default value is 1.

    • If the number of data versions that meet the query conditions exceeds this value, the system returns the specified number of versions in descending order by version 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 columns to read. These can be primary key columns or attribute columns.

    • 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, the system first filters rows based on columnsToGet, then applies columnFilter to the results.

Examples

The following sample code reads two rows with primary key values 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);
            }
        });
    });
});

Use the following sample code as a reference when setting parameters for batch data reads.

  • Read data from multiple tables. Batch read supports reading data from multiple tables in a single request. You can specify 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