Properties

new BigtableClient([options])

Construct an instance of BigtableClient.

Parameters

Name Type Optional Description

options

 

Yes

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Name Type Optional Description

credentials

 

Yes

Credentials object.

credentials.client_email

 

Yes

credentials.private_key

 

Yes

email

 

Yes

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename

 

Yes

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

 

Yes

The port on which to connect to the remote host.

projectId

 

Yes

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

 

Yes

Custom promise module to use instead of native Promises.

servicePath

 

Yes

The domain name of the API remote host.

Properties

static

port

The port for this API service.

static

scopes

The scopes needed to make gRPC calls for every method defined in this service.

static

servicePath

The DNS address for this API service.

Methods

checkAndMutateRow(request[, options][, callback]) → Promise

Mutates a row atomically based on the output of a predicate Reader filter.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
const rowKey = '';
const request = {
  tableName: formattedTableName,
  rowKey: rowKey,
};
client.checkAndMutateRow(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table to which the conditional mutation should be applied. Values are of the form projects/<project>/instances/<instance>/tables/<table>.

rowKey

string

 

The key of the row to which the conditional mutation should be applied.

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

predicateFilter

Object

Yes

The filter to be applied to the contents of the specified row. Depending on whether or not any results are yielded, either true_mutations or false_mutations will be executed. If unset, checks that the row contains any values at all.

This object should have the same structure as RowFilter

trueMutations

Array of Object

Yes

Changes to be atomically applied to the specified row if predicate_filter yields at least one cell when applied to row_key. Entries are applied in order, meaning that earlier mutations can be masked by later ones. Must contain at least one entry if false_mutations is empty, and at most 100000.

This object should have the same structure as Mutation

falseMutations

Array of Object

Yes

Changes to be atomically applied to the specified row if predicate_filter does not yield any cells when applied to row_key. Entries are applied in order, meaning that earlier mutations can be masked by later ones. Must contain at least one entry if true_mutations is empty, and at most 100000.

This object should have the same structure as Mutation

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

function(nullable Error, nullable Object)

Yes

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing CheckAndMutateRowResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing CheckAndMutateRowResponse. The promise has a method named "cancel" which cancels the ongoing API call.

getProjectId(callback)

Return the project ID used by this class.

Parameter

Name Type Optional Description

callback

function(Error, string)

 

the callback to be called with the current project Id.

matchInstanceFromTableName(tableName) → String

Parse the tableName from a table resource.

Parameter

Name Type Optional Description

tableName

String

 

A fully-qualified path representing a table resources.

Returns

String 

  • A string representing the instance.

matchProjectFromTableName(tableName) → String

Parse the tableName from a table resource.

Parameter

Name Type Optional Description

tableName

String

 

A fully-qualified path representing a table resources.

Returns

String 

  • A string representing the project.

matchTableFromTableName(tableName) → String

Parse the tableName from a table resource.

Parameter

Name Type Optional Description

tableName

String

 

A fully-qualified path representing a table resources.

Returns

String 

  • A string representing the table.

mutateRow(request[, options][, callback]) → Promise

Mutates a row atomically. Cells already present in the row are left unchanged unless explicitly changed by mutation.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
const rowKey = '';
const mutations = [];
const request = {
  tableName: formattedTableName,
  rowKey: rowKey,
  mutations: mutations,
};
client.mutateRow(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table to which the mutation should be applied. Values are of the form projects/<project>/instances/<instance>/tables/<table>.

rowKey

string

 

The key of the row to which the mutation should be applied.

mutations

Array of Object

 

Changes to be atomically applied to the specified row. Entries are applied in order, meaning that earlier mutations can be masked by later ones. Must contain at least one entry and at most 100000.

This object should have the same structure as Mutation

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

function(nullable Error, nullable Object)

Yes

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing MutateRowResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing MutateRowResponse. The promise has a method named "cancel" which cancels the ongoing API call.

mutateRows(request[, options]) → Stream

Mutates multiple rows in a batch. Each individual row is mutated atomically as in MutateRow, but the entire batch is not executed atomically.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
const entries = [];
const request = {
  tableName: formattedTableName,
  entries: entries,
};
client.mutateRows(request).on('data', response => {
  // doThingsWith(response)
});

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table to which the mutations should be applied.

entries

Array of Object

 

The row keys and corresponding mutations to be applied in bulk. Each entry is applied as an atomic mutation, but the entries may be applied in arbitrary order (even between entries for the same row). At least one entry must be specified, and in total the entries can contain at most 100000 mutations.

This object should have the same structure as Entry

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns

Stream 

An object stream which emits MutateRowsResponse on 'data' event.

readModifyWriteRow(request[, options][, callback]) → Promise

Modifies a row atomically on the server. The method reads the latest existing timestamp and value from the specified columns and writes a new entry based on pre-defined read/modify/write rules. The new value for the timestamp is the greater of the existing timestamp or the current server time. The method returns the new contents of all modified cells.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
const rowKey = '';
const rules = [];
const request = {
  tableName: formattedTableName,
  rowKey: rowKey,
  rules: rules,
};
client.readModifyWriteRow(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table to which the read/modify/write rules should be applied. Values are of the form projects/<project>/instances/<instance>/tables/<table>.

rowKey

string

 

The key of the row to which the read/modify/write rules should be applied.

rules

Array of Object

 

Rules specifying how the specified row's contents are to be transformed into writes. Entries are applied in order, meaning that earlier rules will affect the results of later ones.

This object should have the same structure as ReadModifyWriteRule

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

function(nullable Error, nullable Object)

Yes

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ReadModifyWriteRowResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing ReadModifyWriteRowResponse. The promise has a method named "cancel" which cancels the ongoing API call.

readRows(request[, options]) → Stream

Streams back the contents of all requested rows in key order, optionally applying the same Reader filter to each. Depending on their size, rows and cells may be broken up across multiple responses, but atomicity of each row will still be preserved. See the ReadRowsResponse documentation for details.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
client.readRows({tableName: formattedTableName}).on('data', response => {
  // doThingsWith(response)
});

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table from which to read. Values are of the form projects/<project>/instances/<instance>/tables/<table>.

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

rows

Object

Yes

The row keys and/or ranges to read. If not specified, reads from all rows.

This object should have the same structure as RowSet

filter

Object

Yes

The filter to apply to the contents of the specified row(s). If unset, reads the entirety of each row.

This object should have the same structure as RowFilter

rowsLimit

number

Yes

The read will terminate after committing to N rows' worth of results. The default (zero) is to return all results.

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns

Stream 

An object stream which emits ReadRowsResponse on 'data' event.

sampleRowKeys(request[, options]) → Stream

Returns a sample of row keys in the table. The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.

Example

const bigtable = require('@google-cloud/bigtable');

const client = new bigtable.v2.BigtableClient({
  // optional auth parameters.
});

const formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]');
client.sampleRowKeys({tableName: formattedTableName}).on('data', response => {
  // doThingsWith(response)
});

Parameters

Name Type Optional Description

request

Object

 

The request object that will be sent.

Values in request have the following properties:

Name Type Optional Description

tableName

string

 

The unique name of the table from which to sample row keys. Values are of the form projects/<project>/instances/<instance>/tables/<table>.

appProfileId

string

Yes

This value specifies routing for replication. If not specified, the "default" application profile will be used.

options

Object

Yes

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns

Stream 

An object stream which emits SampleRowKeysResponse on 'data' event.

tablePath(project, instance, table) → String

Return a fully-qualified table resource name string.

Parameters

Name Type Optional Description

project

String

 

instance

String

 

table

String

 

Returns

String