How to add limit options while fetching data from bigTable ? Can someone give me the proper syntax to do so in NodeJS

Viewed 242

Currenlty I am doing like this

var [rowData] = await table.row(key).get({limit: 2});

Still am getting the 4 results instead of 2.

2 Answers

If you're looking to get 2 columns in an individual row there are a few ways to do that using filters.

You can use the cells per row filter:

const filter = {
    row: {
      cellLimit: 2,
    },
};

await table
    .createReadStream({
    filter,
    })
    .on('error', err => {
    // Handle the error.
    console.log(err);
    })
    .on('data', row => {
    // Use the row data.
    })
    .on('end', () => {
    // All rows retrieved.
    });

You could also do cells per column filter:

const filter = {
    column: {
      cellLimit: 2,
    },
};

The Bigtable filter's documentation is still a WIP, but here are a set of code samples with various filters you can use with your reads.

I don't believe you can do a filter with a single row get, but you can create a scan that only reads that rowkey and it will effectively be the same thing. Let me know if you need more support on this question.

Worked for me:

var filter = [
      {
         family: 'payloads'
      },
      {
         row: {
                key: identifier,
                cellLimit:2
         }
      }
];
Related