All Products
Search
Document Center

Tablestore:Update a single row of data

Last Updated:Jun 22, 2026

Call `updateRow` in the Tablestore Node.js SDK to modify attribute column values, add attribute columns, delete a specific version, or delete an entire attribute column.

Prerequisites

Initialize a Tablestore client

Method

updateRow: function updateRow(params, callback)

Parameters

Name

Type

Description

tableName (Required)

string

The name of the data table.

primaryKey (Required)

Array

The primary key column names and values.

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

  • The number and types of primary keys must be the same as those of the data table.

updateOfAttributeColumns (Required)

Array

The attribute columns to update and the operation type.

condition (Required)

TableStore.Condition

The update condition. For more information, see Conditional update.

returnContent (Optional)

object

The data to return.

  • returnType (Optional) number: The return type.

    • TableStore.ReturnType.NONE: Default value. No data is returned.

    • TableStore.ReturnType.Primarykey: Returns the primary key columns.

    • TableStore.ReturnType.AfterModify: Returns the column values after the update. This is used for atomic counters.

transactionId (Optional)

string

The ID that uniquely identifies a local transaction. For more information, see Local transaction.

Examples

The following example changes the col1 attribute column to changed_val1 for the row whose primary key is row1 in the test_table table.

var params = {
    tableName: 'test_table',
    primaryKey: [{ 'id': 'row1' }],
    // An update condition is required to update a row. TableStore.RowExistenceExpectation.IGNORE means that the row existence is not checked.
    condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};
params.updateOfAttributeColumns = [
    { 'PUT': [{ 'col1': 'changed_val1' }] }
]

client.updateRow(params, function (err, data) {
    if (err) {
        console.log('Update row failed with error:', err);
        return;
    }
    console.log('RequestId: ', data.RequestId);
    console.log('Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('Write CU Cost: ', data.consumed.capacityUnit.write);
});

You can also perform the following operations on the row.

  • Add an attribute column.

    params.updateOfAttributeColumns = [
        { 'PUT': [{ 'col2': 'val2' }] }
    ]
  • Set the version number for an attribute column.

    params.updateOfAttributeColumns = [
        { 'PUT': [{ 'col2': 'val2', 'timestamp': Date.now() }] }
    ]
  • Delete data of a specific version from an attribute column.

    params.updateOfAttributeColumns = [
        { 'DELETE': [{ 'col2': TableStore.Long.fromNumber(1496826473186) }] },
    ]
  • Delete all data from an attribute column.

    params.updateOfAttributeColumns = [
        { 'DELETE_ALL': ['col2'] }
    ]

References

Batch update data