Constructor

FirestoreAdminClient

new FirestoreAdminClient(options)

Construct an instance of FirestoreAdminClient.

Parameter

options

Optional

object

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

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

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

keyFilename

Optional

string

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

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

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

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

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

servicePath

static

The DNS address for this API service.

Methods

createIndex

createIndex(request, options, callback) returns Promise

Creates a composite index. This returns a google.longrunning.Operation which may be used to track the status of the creation. The metadata for the operation will be the type IndexOperationMetadata.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

A parent name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}

index

Object

The composite index to create.

This object should have the same structure as Index

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]'); const index = {}; const request = { parent:
formattedParent, index: index,
};
client.createIndex(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

databasePath

databasePath(project, database) returns String

Return a fully-qualified database resource name string.

Parameter

project

String

database

String

Returns

String 

deleteIndex

deleteIndex(request, options, callback) returns Promise

Deletes a composite index.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

A name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}

options

Optional

Object

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

callback

Optional

function(nullable Error)

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

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedName = client.indexPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]', '[INDEX_ID]'); client.deleteIndex({name:
formattedName}).catch(err => { console.error(err);
});

exportDocuments

exportDocuments(request, options, callback) returns Promise

Exports a copy of all or a subset of documents from Google Cloud Firestore to another storage system, such as Google Cloud Storage. Recent updates to documents may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

Database to export. Should be of the form: projects/{project_id}/databases/{database_id}.

collectionIds

Optional

Array of string

Which collection ids to export. Unspecified means all collections.

outputUriPrefix

Optional

string

The output URI. Currently only supports Google Cloud Storage URIs of the form: gs://BUCKET_NAME[/NAMESPACE_PATH], where BUCKET_NAME is the name of the Google Cloud Storage bucket and NAMESPACE_PATH is an optional Google Cloud Storage namespace path. When choosing a name, be sure to consider Google Cloud Storage naming guidelines: https://cloud.google.com/storage/docs/naming. If the URI is a bucket (without a namespace path), a prefix will be generated based on the start time.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedName = client.databasePath('[PROJECT]', '[DATABASE]');
client.exportDocuments({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

fieldPath

fieldPath(project, database, collectionId, fieldId) returns String

Return a fully-qualified field resource name string.

Parameter

project

String

database

String

collectionId

String

fieldId

String

Returns

String 

getField

getField(request, options, callback) returns Promise

Gets the metadata and configuration for a Field.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

A name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/fields/{field_id}

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedName = client.fieldPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]', '[FIELD_ID]'); client.getField({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getIndex

getIndex(request, options, callback) returns Promise

Gets a composite index.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

A name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedName = client.indexPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]', '[INDEX_ID]'); client.getIndex({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

importDocuments

importDocuments(request, options, callback) returns Promise

Imports documents into Google Cloud Firestore. Existing documents with the same name are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportDocuments operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Firestore.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

Database to import into. Should be of the form: projects/{project_id}/databases/{database_id}.

collectionIds

Optional

Array of string

Which collection ids to import. Unspecified means all collections included in the import.

inputUriPrefix

Optional

string

Location of the exported files. This must match the output_uri_prefix of an ExportDocumentsResponse from an export that has completed successfully. See: google.firestore.admin.v1.ExportDocumentsResponse.output_uri_prefix.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedName = client.databasePath('[PROJECT]', '[DATABASE]');
client.importDocuments({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

indexPath

indexPath(project, database, collectionId, indexId) returns String

Return a fully-qualified index resource name string.

Parameter

project

String

database

String

collectionId

String

indexId

String

Returns

String 

listFields

listFields(request, options, callback) returns Promise

Lists the field configuration and metadata for this database.

Currently, FirestoreAdmin.ListFields only supports listing fields that have been explicitly overridden. To issue this query, call FirestoreAdmin.ListFields with the filter set to indexConfig.usesAncestorConfig:false.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

A parent name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}

filter

Optional

string

The filter to apply to list results. Currently, FirestoreAdmin.ListFields only supports listing fields that have been explicitly overridden. To issue this query, call FirestoreAdmin.ListFields with the filter set to indexConfig.usesAncestorConfig:false.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

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

The second parameter to the callback is Array of Field.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListFieldsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of Field.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Field in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListFieldsResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]');

client.listFields({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listFields(nextRequest, options).then(callback);
  }
}
client.listFields({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listFieldsStream

listFieldsStream(request, options) returns Stream

Equivalent to listFields, but returns a NodeJS Stream object.

This fetches the paged responses for listFields continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

A parent name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}

filter

Optional

string

The filter to apply to list results. Currently, FirestoreAdmin.ListFields only supports listing fields that have been explicitly overridden. To issue this query, call FirestoreAdmin.ListFields with the filter set to indexConfig.usesAncestorConfig:false.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

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

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing Field on 'data' event.

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]'); client.listFieldsStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listIndexes

listIndexes(request, options, callback) returns Promise

Lists composite indexes.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

A parent name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}

filter

Optional

string

The filter to apply to list results.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

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

The second parameter to the callback is Array of Index.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListIndexesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of Index.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Index in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListIndexesResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]');

client.listIndexes({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listIndexes(nextRequest, options).then(callback);
  }
}
client.listIndexes({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listIndexesStream

listIndexesStream(request, options) returns Stream

Equivalent to listIndexes, but returns a NodeJS Stream object.

This fetches the paged responses for listIndexes continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

A parent name of the form projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}

filter

Optional

string

The filter to apply to list results.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

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

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing Index on 'data' event.

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const formattedParent = client.parentPath('[PROJECT]', '[DATABASE]',
'[COLLECTION_ID]'); client.listIndexesStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

matchCollectionIdFromFieldName

matchCollectionIdFromFieldName(fieldName) returns String

Parse the fieldName from a field resource.

Parameter

fieldName

String

A fully-qualified path representing a field resources.

Returns

String 

  • A string representing the collection_id.

matchCollectionIdFromIndexName

matchCollectionIdFromIndexName(indexName) returns String

Parse the indexName from a index resource.

Parameter

indexName

String

A fully-qualified path representing a index resources.

Returns

String 

  • A string representing the collection_id.

matchCollectionIdFromParentName

matchCollectionIdFromParentName(parentName) returns String

Parse the parentName from a parent resource.

Parameter

parentName

String

A fully-qualified path representing a parent resources.

Returns

String 

  • A string representing the collection_id.

matchDatabaseFromDatabaseName

matchDatabaseFromDatabaseName(databaseName) returns String

Parse the databaseName from a database resource.

Parameter

databaseName

String

A fully-qualified path representing a database resources.

Returns

String 

  • A string representing the database.

matchDatabaseFromFieldName

matchDatabaseFromFieldName(fieldName) returns String

Parse the fieldName from a field resource.

Parameter

fieldName

String

A fully-qualified path representing a field resources.

Returns

String 

  • A string representing the database.

matchDatabaseFromIndexName

matchDatabaseFromIndexName(indexName) returns String

Parse the indexName from a index resource.

Parameter

indexName

String

A fully-qualified path representing a index resources.

Returns

String 

  • A string representing the database.

matchDatabaseFromParentName

matchDatabaseFromParentName(parentName) returns String

Parse the parentName from a parent resource.

Parameter

parentName

String

A fully-qualified path representing a parent resources.

Returns

String 

  • A string representing the database.

matchFieldIdFromFieldName

matchFieldIdFromFieldName(fieldName) returns String

Parse the fieldName from a field resource.

Parameter

fieldName

String

A fully-qualified path representing a field resources.

Returns

String 

  • A string representing the field_id.

matchIndexIdFromIndexName

matchIndexIdFromIndexName(indexName) returns String

Parse the indexName from a index resource.

Parameter

indexName

String

A fully-qualified path representing a index resources.

Returns

String 

  • A string representing the index_id.

matchProjectFromDatabaseName

matchProjectFromDatabaseName(databaseName) returns String

Parse the databaseName from a database resource.

Parameter

databaseName

String

A fully-qualified path representing a database resources.

Returns

String 

  • A string representing the project.

matchProjectFromFieldName

matchProjectFromFieldName(fieldName) returns String

Parse the fieldName from a field resource.

Parameter

fieldName

String

A fully-qualified path representing a field resources.

Returns

String 

  • A string representing the project.

matchProjectFromIndexName

matchProjectFromIndexName(indexName) returns String

Parse the indexName from a index resource.

Parameter

indexName

String

A fully-qualified path representing a index resources.

Returns

String 

  • A string representing the project.

matchProjectFromParentName

matchProjectFromParentName(parentName) returns String

Parse the parentName from a parent resource.

Parameter

parentName

String

A fully-qualified path representing a parent resources.

Returns

String 

  • A string representing the project.

parentPath

parentPath(project, database, collectionId) returns String

Return a fully-qualified parent resource name string.

Parameter

project

String

database

String

collectionId

String

Returns

String 

updateField

updateField(request, options, callback) returns Promise

Updates a field configuration. Currently, field updates apply only to single field index configuration. However, calls to FirestoreAdmin.UpdateField should provide a field mask to avoid changing any configuration that the caller isn't aware of. The field mask should be specified as: { paths: "index_config" }.

This call returns a google.longrunning.Operation which may be used to track the status of the field update. The metadata for the operation will be the type FieldOperationMetadata.

To configure the default field settings for the database, use the special Field with resource name: projects/{project_id}/databases/{database_id}/collectionGroups/default/fields/*.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

field

Object

The field to be updated.

This object should have the same structure as Field

updateMask

Optional

Object

A mask, relative to the field. If specified, only configuration specified by this field_mask will be updated in the field.

This object should have the same structure as FieldMask

options

Optional

Object

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

callback

Optional

function(nullable Error, nullable Object)

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

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

Returns

Promise 

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

Example

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

const client = new firestore.v1.FirestoreAdminClient({
  // optional auth parameters.
});

const field = {};
client.updateField({field: field})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });