All Products
Search
Document Center

Tablestore:Update a single row of data

更新时间:Mar 12, 2026

Update a single row in a Tablestore table by calling `updateRow` in the Node.js SDK. 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 information, which includes 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 information about 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 content of 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 local transaction ID. This ID uniquely identifies a local transaction. For more information, see Local transaction.

Examples

The following sample code changes the value of 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);
});

Also perform the following row operations.

  • 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