Class Bigtable (6.0.0)

Package

@google-cloud/bigtable

Examples

Create a client that usesApplication Default Credentials (ADC):

const{Bigtable}=require('@google-cloud/bigtable');constbigtable=newBigtable();

Create a client withexplicit credentials:

const{Bigtable}=require('@google-cloud/bigtable');constbigtable=newBigtable({projectId:'your-project-id',keyFilename:'/path/to/keyfile.json'});

The Bigtable Emulator

// Make sure you have the {@link https://cloud.google.com/sdk/downloads gcloud SDK installed}, then run:$gcloudbetaemulatorsbigtablestart// Before running your Node.js app, set the environment variables that this// library will look for to connect to the emulator:$$(gcloudbetaemulatorsbigtableenv-init)

Creating a Bigtable Instance and Cluster

// Before you create your table, you first need to create a Bigtable Instance// and cluster for the table to be served from.const{Bigtable}=require('@google-cloud/bigtable');constbigtable=newBigtable();constcallback=(err,instance,operation)=>{operation.on('error',console.log).on('complete',()=>{// `instance` is your newly created Instance object.});};constinstance=bigtable.instance('my-instance');instance.create({clusters:[{id:'my-cluster',location:'us-central1-b',nodes:3}]},callback);// This can also be done from either the Google Cloud Platform Console or the// `gcloud` cli tool. Please refer to the// {@link https://cloud.google.com/bigtable/docs/creating-instance official Bigtable documentation}// for more information.

Creating Tables

// After creating your instance and enabling the Bigtable APIs, you are now// ready to create your table with {@link Instance#createTable}.instance.createTable('prezzy',function(err,table){// `table` is your newly created Table object.});

Creating Column Families

// Column families are used to group together various pieces of data within// your table. You can think of column families as a mechanism to categorize// all of your data.//// We can create a column family with {@link Table#createFamily}.consttable=instance.table('prezzy');table.createFamily('follows',function(err,family){// `family` is your newly created Family object.});// It is also possible to create your column families when creating a new// table.constoptions={families:['follows']};instance.createTable('prezzy',options,function(err,table){});

Creating Rows

// New rows can be created within your table using// {@link Table#insert}. You must provide a unique key for each row// to be inserted, this key can then be used to retrieve your row at a later// time.//// With Bigtable, all columns have a unique id composed of a column family// and a column qualifier. In the example below `follows` is the column// family and `tjefferson` is the column qualifier. Together they could be// referred to as `follows:tjefferson`.constrows=[{key:'wmckinley',data:{follows:{tjefferson:1}}}];table.insert(rows,err=>{if(!err){// Your rows were successfully inserted.}});

Retrieving Rows

// If you're anticipating a large number of rows to be returned, we suggest// using the {@link Table#getRows} streaming API.table.createReadStream().on('error',console.error).on('data',row=>{// `row` is a Row object.});// If you're not anticpating a large number of results, a callback mode// is also available.constcallback=(err,rows)=>{// `rows` is an array of Row objects.};table.getRows(callback);// A range of rows can be retrieved by providing `start` and `end` row keys.constoptions={start:'gwashington',end:'wmckinley'};table.getRows(options,callback);// Retrieve an individual row with {@link Row#get}.constrow=table.row('alincoln');row.get(err=>{// `row.data` is now populated.});

Accessing Row Data

// When retrieving rows, upon success the `row.data` property will be// populated by an object. That object will contain additional objects// for each family in your table that the row has data for.//// By default, when retrieving rows, each column qualifier will provide you// with all previous versions of the data. So your `row.data` object could// resemble the following.{follows:{wmckinley:[{value:1,timestamp:1466017315951},{value:2,timestamp:1458619200000}]}}// The `timestamp` field can be used to order cells from newest to oldest.// If you only wish to retrieve the most recent version of the data, you// can specify the number of cells with a {@link Filter} object.constfilter=[{column:{cellLimit:1}}];table.getRows({filter:filter},callback);

Deleting Row Data

// We can delete all of an individual row's cells using {@link Row#delete}.constcallback=err=>{if(!err){// All cells for this row were deleted successfully.}};row.delete(callback);// To delete a specific set of cells, we can provide an array of// column families and qualifiers.constcells=['follows:gwashington','traits'];row.delete(cells,callback);

Deleting Rows

// If you wish to delete multiple rows entirely, we can do so with// {@link Table#deleteRows}. You can provide this method with a// row key prefix.constoptions={prefix:'gwash'};table.deleteRows(options,err=>{if(!err){// Rows were deleted successfully.}});// If you omit the prefix, you can delete all rows in your table.table.deleteRows(err=>{if(!err){// All rows were deleted successfully.}});

Constructors

(constructor)(options)

constructor(options?:BigtableOptions);

Constructs a new instance of theBigtable class

Parameter
NameDescription
optionsBigtableOptions

Properties

api

api:{[index:string]:v2.BigtableClient|v2.BigtableInstanceAdminClient|v2.BigtableTableAdminClient;};

AppProfile

staticAppProfile:AppProfile;

appProfileId

appProfileId?:string;

auth

auth:GoogleAuth;

Cluster

staticCluster:Cluster;

customEndpoint

customEndpoint?:string;

Instance

staticInstance:Instance;

options

options:BigtableOptions;

projectId

projectId:string;

projectName

projectName:string;

shouldReplaceProjectIdToken

shouldReplaceProjectIdToken:boolean;

Methods

close()

close():Promise<void[]>;

Close all bigtable clients. New requests will be rejected but it will not kill connections with pending requests.

Returns
TypeDescription
Promise<void[]>

createInstance(id, options)

createInstance(id:string,options:InstanceOptions):Promise<CreateInstanceResponse>;
Parameters
NameDescription
idstring
optionsInstanceOptions
Returns
TypeDescription
Promise<CreateInstanceResponse>

createInstance(id, options, callback)

createInstance(id:string,options:InstanceOptions,callback:CreateInstanceCallback):void;
Parameters
NameDescription
idstring
optionsInstanceOptions
callbackCreateInstanceCallback
Returns
TypeDescription
void

getInstances(gaxOptions)

getInstances(gaxOptions?:CallOptions):Promise<GetInstancesResponse>;
Parameter
NameDescription
gaxOptionsCallOptions
Returns
TypeDescription
Promise<GetInstancesResponse>

getInstances(callback)

getInstances(callback:GetInstancesCallback):void;
Parameter
NameDescription
callbackGetInstancesCallback
Returns
TypeDescription
void

getInstances(gaxOptions, callback)

getInstances(gaxOptions:CallOptions,callback:GetInstancesCallback):void;
Parameters
NameDescription
gaxOptionsCallOptions
callbackGetInstancesCallback
Returns
TypeDescription
void

getProjectId_(callback)

getProjectId_(callback:(err:Error|null,projectId?:string)=>void):void;

Determine and localize the project ID. If a user provides an ID, we bypass checking with the auth client for an ID.

Parameter
NameDescription
callback(err:Error | null, projectId?: string) => void

Callback function.

Returns
TypeDescription
void

instance(name)

instance(name:string):Instance;

Get a reference to a Cloud Bigtable instance.

Parameter
NameDescription
namestring
Returns
TypeDescription
Instance

{Instance}

request(config)

request<T=any>(config?:any):AbortableDuplex;
Parameter
NameDescription
configany
Returns
TypeDescription
AbortableDuplex
Type Parameter
NameDescription
T

request(config, callback)

request<T=any>(config?:any,callback?:RequestCallback<T>):void;
Parameters
NameDescription
configany
callbackRequestCallback<T>
Returns
TypeDescription
void
Type Parameter
NameDescription
T

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.