All Products
Search
Document Center

Tablestore:Write a single row of data

Last Updated:Mar 11, 2026

This topic describes how to write a single row of data to a Tablestore table using the Tablestore Node.js SDK.

Prerequisites

Initialize the Tablestore client

Method description

putRow: function putRow(params, callback)

Parameter descriptions

Name

Type

Description

tableName (required)

string

The name of the table.

primaryKey (required)

Array

The primary key information, including the names and values of primary key columns.

  • Primary key column data types include STRING, INTEGER, and BINARY.

  • The number and types of primary keys in the row must match those defined for the table.

  • If a primary key column is an auto-increment column, set its value to a placeholder. For more information, see auto-increment primary key column.

attributeColumns (optional)

Array

The attribute column information, including the names, values, and version numbers of attribute columns.

  • Attribute column data types include STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

  • The version number is a timestamp. By default, the system generates it automatically. You can also specify it manually. For more information, see data versions and lifecycle.

condition (required)

TableStore.Condition

The write condition. For more information, see conditional update.

returnContent (optional)

object

The data to return.

  • returnType (optional) number: The return type.

    • TableStore.ReturnType.NONE (default): Returns no data.

    • TableStore.ReturnType.Primarykey: Returns the primary key columns. Use this option for auto-increment primary key columns.

    • TableStore.ReturnType.AfterModify: Returns the updated column values. Use this option for atomic counters.

transactionId (optional)

string

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

Example code

The following example writes one row of data to the test_table table. The primary key value of the row is row1.

var params = {
    tableName: 'test_table',
    primaryKey: [{ 'id': 'row1' }],
    // Specify a write condition when writing data. TableStore.RowExistenceExpectation.IGNORE means that the system does not check whether the row exists.
    condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};

client.putRow(params, function (err, data) {
    if (err) {
        console.log('Put 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);
});
  • Add an attribute column.

    params.attributeColumns = [{ 'col1': 'val1' }];
  • Specify a version number. You can assign a separate version number to each attribute column.

    params.attributeColumns = [{ 'col1': 'val1', 'timestamp': Date.now() }];

References

Batch update data