Read multiple rows from one or more Tablestore tables in a single request by using the `batchGetRow` method in the Node.js SDK.
Notes
A single batch read operation supports reading up to 100 rows of data.
Prerequisites
Method
batchGetRow: function batchGetRow(params, callback)
Examples
The following sample code reads two rows with primary key values row1 and row2 from the test_table table.
var table = {
// Set the table name
tableName: 'test_table',
primaryKey: [
// Add primary key information for row 1
[{ 'id': 'row1' }],
// Add primary key information for row 2
[{ 'id': 'row2' }]
]
};
var params = {
tables: [
table
]
}
// Call the batchGetRow method to perform a batch data query
client.batchGetRow(params, function (err, data) {
if (err) {
console.log('Batch get row failed with error: ', err);
return;
}
// Process the response
console.log('* RequestId: ', data.RequestId);
console.log('* Rows Data: ');
data.tables.forEach(function (rows) {
rows.forEach(function (row) {
if (row.isOk) {
console.log('Succeeded Row:', row.tableName, JSON.stringify(row.primaryKey), JSON.stringify(row.attributes));
} else {
console.log('Failed Row:', row.tableName, row.errorMessage);
}
});
});
});
Use the following sample code as a reference when setting parameters for batch data reads.
-
Read data from multiple tables. Batch read supports reading data from multiple tables in a single request. You can specify query conditions for each table.
var table1 = { tableName: 'orders_small', primaryKey: [ [{ 'order_id': '90fb478c-1360-11f0-a34d-00163e30a2a9' }] ] }; var params = { tables: [ table, table1 ] }; -
Set a data version range. Only data within the specified range is returned.
// Set the version range to the past 24 hours from the current time table.timeRange = { startTime: (Date.now() - 86400 * 1000).toString(), endTime: Date.now().toString() } -
Specify attribute columns to read.
table.columnsToGet = ['col2']