All Products
Search
Document Center

Tablestore:Read a single row of data

Last Updated:Mar 12, 2026

Read a single row from a Tablestore table by calling `getRow` in the Node.js SDK. Specify primary key values, version ranges, and column filters to control the returned data.

Notes

You must provide the complete primary key value to read data. This value includes the value of the auto-increment primary key column.

Prerequisites

Initialize a Tablestore client

Method

getRow: function getRow(params, callback)

Parameter description

Name

Type

Description

tableName (Required)

string

The name of the data table.

primaryKey (Required)

Array

The information about the primary key. This includes the names and values of the primary key columns.

  • The data types of primary key columns can be STRING, INTEGER, or BINARY.

  • The number and types of primary keys must match those of the data table.

maxVersions (Optional)

number

The maximum number of versions to return. The default value is 1.

  • If the number of data versions that meet the query condition exceeds the specified maximum number of versions, the specified number of versions are returned from newest to oldest.

timeRange (Optional)

object

Specifies the range of data versions.

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

columnsToGet (Optional)

Array

The data columns to read. These can be primary key columns or attribute columns.

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

  • If you set columnsToGet and the row to read does not contain any of the specified data columns, null is returned.

columnFilter (Optional)

TableStore.ColumnCondition

The filter condition. For more information, see Filters.

  • If you set both columnsToGet and columnFilter, the system first selects rows based on columnsToGet. Then, it filters the data based on columnFilter.

transactionId (Optional)

string

The ID of the local transaction. This ID uniquely identifies a local transaction. For more information, see Local transactions.

Examples

The following sample code shows how to read a single row of data where the primary key value is row1.

var params = {
    tableName: 'test_table',
    primaryKey: [{ 'id': 'row1' }]
};

client.getRow(params, function (err, data) {
    if (err) {
        console.log('Get row failed with error: ', err);
        return;
    }
    console.log('Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('Write CU Cost: ', data.consumed.capacityUnit.write);
    console.log('Row Data: ', JSON.stringify(data.row));
});
  • Set a time range for the data versions to read. Only data within the specified time range is returned.

    params.timeRange = {
        startTime: (Date.now() - 86400 * 1000).toString(),
        endTime: Date.now().toString()
    }
  • Specify the attribute columns to read.

    params.columnsToGet = ['col2']

References