This topic describes how to write a single row of data to a Tablestore table using the Tablestore Node.js SDK.
Prerequisites
Method description
putRow: function putRow(params, callback)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