Package com.google.cloud.firestore.v1 (3.20.0)

A client to Cloud Firestore API

The interfaces provided are listed below, along with usage samples.

FirestoreClient

Service Description: The Cloud Firestore service.

Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simplifies storing, syncing, and querying data for your mobile, web, and IoT apps at global scale. Its client libraries provide live synchronization and offline support, while its security features and integrations with Firebase and Google Cloud Platform accelerate building truly serverless apps.

Sample for FirestoreClient:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (FirestoreClient firestoreClient = FirestoreClient.create()) {
   GetDocumentRequest request =
       GetDocumentRequest.newBuilder()
           .setName("name3373707")
           .setMask(DocumentMask.newBuilder().build())
           .build();
   Document response = firestoreClient.getDocument(request);
 }
 

Classes

FirestoreAdminClient

Service Description: The Cloud Firestore Admin API.

This API provides several administrative services for Cloud Firestore.

Project, Database, Namespace, Collection, Collection Group, and Document are used as defined in the Google Cloud Firestore API.

Operation: An Operation represents work being performed in the background.

The index service manages Cloud Firestore indexes.

Index creation is performed asynchronously. An Operation resource is created for each such asynchronous operation. The state of the operation (including any errors encountered) may be queried via the Operation resource.

The Operations collection provides a record of actions performed for the specified Project (including any Operations in progress). Operations are not created directly but through calls on other collections or resources.

An Operation that is done may be deleted so that it is no longer listed as part of the Operation collection. Operations are garbage collected after 30 days. By default, ListOperations will only return in progress and failed operations. To list completed operation, issue a ListOperations request with the filter done: true.

Operations are created by service FirestoreAdmin, but are accessed via service google.longrunning.Operations.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
   IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
   Index response = firestoreAdminClient.getIndex(name);
 }
 

Note: close() needs to be called on the FirestoreAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
MethodDescriptionMethod Variants

CreateIndex

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createIndexAsync(CreateIndexRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • createIndexAsync(CollectionGroupName parent, Index index)

  • createIndexAsync(String parent, Index index)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createIndexOperationCallable()

  • createIndexCallable()

ListIndexes

Lists composite indexes.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listIndexes(ListIndexesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listIndexes(CollectionGroupName parent)

  • listIndexes(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listIndexesPagedCallable()

  • listIndexesCallable()

GetIndex

Gets a composite index.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIndex(GetIndexRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getIndex(IndexName name)

  • getIndex(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIndexCallable()

DeleteIndex

Deletes a composite index.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteIndex(DeleteIndexRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteIndex(IndexName name)

  • deleteIndex(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteIndexCallable()

GetField

Gets the metadata and configuration for a Field.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getField(GetFieldRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getField(FieldName name)

  • getField(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getFieldCallable()

UpdateField

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/*.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateFieldAsync(UpdateFieldRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateFieldAsync(Field field)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateFieldOperationCallable()

  • updateFieldCallable()

ListFields

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 or ttlConfig:*.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listFields(ListFieldsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listFields(CollectionGroupName parent)

  • listFields(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listFieldsPagedCallable()

  • listFieldsCallable()

ExportDocuments

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.

For more details on export behavior and output format, refer to: https://cloud.google.com/firestore/docs/manage-data/export-import

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • exportDocumentsAsync(ExportDocumentsRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • exportDocumentsAsync(DatabaseName name)

  • exportDocumentsAsync(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • exportDocumentsOperationCallable()

  • exportDocumentsCallable()

ImportDocuments

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • importDocumentsAsync(ImportDocumentsRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • importDocumentsAsync(DatabaseName name)

  • importDocumentsAsync(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • importDocumentsOperationCallable()

  • importDocumentsCallable()

CreateDatabase

Create a database.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createDatabaseAsync(CreateDatabaseRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • createDatabaseAsync(ProjectName parent, Database database, String databaseId)

  • createDatabaseAsync(String parent, Database database, String databaseId)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createDatabaseOperationCallable()

  • createDatabaseCallable()

GetDatabase

Gets information about a database.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getDatabase(GetDatabaseRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getDatabase(DatabaseName name)

  • getDatabase(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getDatabaseCallable()

ListDatabases

List all the databases in the project.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listDatabases(ListDatabasesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listDatabases(ProjectName parent)

  • listDatabases(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listDatabasesCallable()

UpdateDatabase

Updates a database.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateDatabaseAsync(UpdateDatabaseRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateDatabaseAsync(Database database, FieldMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateDatabaseOperationCallable()

  • updateDatabaseCallable()

DeleteDatabase

Deletes a database.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteDatabaseAsync(DeleteDatabaseRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteDatabaseAsync(DatabaseName name)

  • deleteDatabaseAsync(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteDatabaseOperationCallable()

  • deleteDatabaseCallable()

GetBackup

Gets information about a backup.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getBackup(GetBackupRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getBackup(BackupName name)

  • getBackup(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getBackupCallable()

ListBackups

Lists all the backups.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listBackups(ListBackupsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listBackups(LocationName parent)

  • listBackups(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listBackupsCallable()

DeleteBackup

Deletes a backup.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteBackup(DeleteBackupRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteBackup(BackupName name)

  • deleteBackup(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteBackupCallable()

RestoreDatabase

Creates a new database by restoring from an existing backup.

The new database must be in the same cloud region or multi-region location as the existing backup. This behaves similar to FirestoreAdmin.CreateDatabase except instead of creating a new empty database, a new database is created with the database type, index configuration, and documents from an existing backup.

The long-running operation can be used to track the progress of the restore, with the Operation's metadata field type being the RestoreDatabaseMetadata. The response type is the Database if the restore was successful. The new database is not readable or writeable until the LRO has completed.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • restoreDatabaseAsync(RestoreDatabaseRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • restoreDatabaseOperationCallable()

  • restoreDatabaseCallable()

CreateBackupSchedule

Creates a backup schedule on a database. At most two backup schedules can be configured on a database, one daily backup schedule with retention up to 7 days and one weekly backup schedule with retention up to 14 weeks.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createBackupSchedule(CreateBackupScheduleRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • createBackupSchedule(DatabaseName parent, BackupSchedule backupSchedule)

  • createBackupSchedule(String parent, BackupSchedule backupSchedule)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createBackupScheduleCallable()

GetBackupSchedule

Gets information about a backup schedule.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getBackupSchedule(GetBackupScheduleRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getBackupSchedule(BackupScheduleName name)

  • getBackupSchedule(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getBackupScheduleCallable()

ListBackupSchedules

List backup schedules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listBackupSchedules(ListBackupSchedulesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listBackupSchedules(DatabaseName parent)

  • listBackupSchedules(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listBackupSchedulesCallable()

UpdateBackupSchedule

Updates a backup schedule.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateBackupSchedule(UpdateBackupScheduleRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • updateBackupSchedule(BackupSchedule backupSchedule, FieldMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateBackupScheduleCallable()

DeleteBackupSchedule

Deletes a backup schedule.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteBackupSchedule(DeleteBackupScheduleRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteBackupSchedule(BackupScheduleName name)

  • deleteBackupSchedule(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteBackupScheduleCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of FirestoreAdminSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreAdminSettings firestoreAdminSettings =
     FirestoreAdminSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create(firestoreAdminSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreAdminSettings firestoreAdminSettings =
     FirestoreAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
 FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create(firestoreAdminSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreAdminSettings firestoreAdminSettings =
     FirestoreAdminSettings.newHttpJsonBuilder().build();
 FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create(firestoreAdminSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

FirestoreAdminClient.ListFieldsFixedSizeCollection

FirestoreAdminClient.ListFieldsPage

FirestoreAdminClient.ListFieldsPagedResponse

FirestoreAdminClient.ListIndexesFixedSizeCollection

FirestoreAdminClient.ListIndexesPage

FirestoreAdminClient.ListIndexesPagedResponse

FirestoreAdminSettings

Settings class to configure an instance of FirestoreAdminClient.

The default instance has everything set to sensible defaults:

  • The default service address (firestore.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of getIndex to 30 seconds:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreAdminSettings.Builder firestoreAdminSettingsBuilder =
     FirestoreAdminSettings.newBuilder();
 firestoreAdminSettingsBuilder
     .getIndexSettings()
     .setRetrySettings(
         firestoreAdminSettingsBuilder
             .getIndexSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 FirestoreAdminSettings firestoreAdminSettings = firestoreAdminSettingsBuilder.build();
 

FirestoreAdminSettings.Builder

Builder for FirestoreAdminSettings.

FirestoreClient

Service Description: The Cloud Firestore service.

Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simplifies storing, syncing, and querying data for your mobile, web, and IoT apps at global scale. Its client libraries provide live synchronization and offline support, while its security features and integrations with Firebase and Google Cloud Platform accelerate building truly serverless apps.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (FirestoreClient firestoreClient = FirestoreClient.create()) {
   GetDocumentRequest request =
       GetDocumentRequest.newBuilder()
           .setName("name3373707")
           .setMask(DocumentMask.newBuilder().build())
           .build();
   Document response = firestoreClient.getDocument(request);
 }
 

Note: close() needs to be called on the FirestoreClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
MethodDescriptionMethod Variants

GetDocument

Gets a single document.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getDocument(GetDocumentRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getDocumentCallable()

ListDocuments

Lists documents.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listDocuments(ListDocumentsRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listDocumentsPagedCallable()

  • listDocumentsCallable()

UpdateDocument

Updates or inserts a document.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateDocument(UpdateDocumentRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • updateDocument(Document document, DocumentMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateDocumentCallable()

DeleteDocument

Deletes a document.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteDocument(DeleteDocumentRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteDocument(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteDocumentCallable()

BatchGetDocuments

Gets multiple documents.

Documents returned by this method are not guaranteed to be returned in the same order that they were requested.

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • batchGetDocumentsCallable()

BeginTransaction

Starts a new transaction.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • beginTransaction(BeginTransactionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • beginTransaction(String database)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • beginTransactionCallable()

Commit

Commits a transaction, while optionally updating documents.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • commit(CommitRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • commit(String database, List<Write> writes)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • commitCallable()

Rollback

Rolls back a transaction.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • rollback(RollbackRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • rollback(String database, ByteString transaction)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • rollbackCallable()

RunQuery

Runs a query.

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • runQueryCallable()

RunAggregationQuery

Runs an aggregation query.

Rather than producing Document results like Firestore.RunQuery, this API allows running an aggregation to produce a series of AggregationResult server-side.

High-Level Example:

<code><code> -- Return the number of documents in table given a filter. SELECT COUNT(&#42;) FROM ( SELECT &#42; FROM k where a = true ); </code></code>

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • runAggregationQueryCallable()

PartitionQuery

Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • partitionQuery(PartitionQueryRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • partitionQueryPagedCallable()

  • partitionQueryCallable()

Write

Streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • writeCallable()

Listen

Listens to changes. This method is only available via gRPC or WebChannel (not REST).

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listenCallable()

ListCollectionIds

Lists all the collection IDs underneath a document.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listCollectionIds(ListCollectionIdsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listCollectionIds(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listCollectionIdsPagedCallable()

  • listCollectionIdsCallable()

BatchWrite

Applies a batch of write operations.

The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write.

If you require an atomically applied set of writes, use Commit instead.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • batchWrite(BatchWriteRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • batchWriteCallable()

CreateDocument

Creates a new document.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createDocument(CreateDocumentRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createDocumentCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of FirestoreSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreSettings firestoreSettings =
     FirestoreSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 FirestoreClient firestoreClient = FirestoreClient.create(firestoreSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreSettings firestoreSettings =
     FirestoreSettings.newBuilder().setEndpoint(myEndpoint).build();
 FirestoreClient firestoreClient = FirestoreClient.create(firestoreSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreSettings firestoreSettings = FirestoreSettings.newHttpJsonBuilder().build();
 FirestoreClient firestoreClient = FirestoreClient.create(firestoreSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

FirestoreClient.ListCollectionIdsFixedSizeCollection

FirestoreClient.ListCollectionIdsPage

FirestoreClient.ListCollectionIdsPagedResponse

FirestoreClient.ListDocumentsFixedSizeCollection

FirestoreClient.ListDocumentsPage

FirestoreClient.ListDocumentsPagedResponse

FirestoreClient.PartitionQueryFixedSizeCollection

FirestoreClient.PartitionQueryPage

FirestoreClient.PartitionQueryPagedResponse

FirestoreSettings

Settings class to configure an instance of FirestoreClient.

The default instance has everything set to sensible defaults:

  • The default service address (firestore.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of getDocument to 30 seconds:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 FirestoreSettings.Builder firestoreSettingsBuilder = FirestoreSettings.newBuilder();
 firestoreSettingsBuilder
     .getDocumentSettings()
     .setRetrySettings(
         firestoreSettingsBuilder
             .getDocumentSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 FirestoreSettings firestoreSettings = firestoreSettingsBuilder.build();
 

FirestoreSettings.Builder

Builder for FirestoreSettings.