Interface Firestore (3.5.0)

Stay organized with collections Save and categorize content based on your preferences.
public interface Firestore extends Service<FirestoreOptions>, AutoCloseable

Represents a Firestore Database and is the entry point for all Firestore operations

Implements

com.google.cloud.Service<com.google.cloud.firestore.FirestoreOptions>, AutoCloseable

Methods

<T>runAsyncTransaction(Transaction.AsyncFunction<T> updateFunction)

public abstract ApiFuture<T> <T>runAsyncTransaction(Transaction.AsyncFunction<T> updateFunction)

Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, the updateFunction will be retried. If it fails to commit after 5 attempts, the transaction will fail.

Running a transaction places locks all consumed documents. To unblock other clients, the Firestore backend automatically releases all locks after 60 seconds of inactivity and fails all transactions that last longer than 270 seconds (see Firestore Quotas).

Parameter
NameDescription
updateFunctionAsyncFunction<T>

The function to execute within the transaction context.

Returns
TypeDescription
ApiFuture<T>

An ApiFuture that will be resolved with the result from updateFunction.

<T>runAsyncTransaction(Transaction.AsyncFunction<T> updateFunction, TransactionOptions transactionOptions)

public abstract ApiFuture<T> <T>runAsyncTransaction(Transaction.AsyncFunction<T> updateFunction, TransactionOptions transactionOptions)

Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, the updateFunction will be retried. If it fails to commit after the maxmimum number of attemps specified in transactionOptions, the transaction will fail.

Running a transaction places locks all consumed documents. To unblock other clients, the Firestore backend automatically releases all locks after 60 seconds of inactivity and fails all transactions that last longer than 270 seconds (see Firestore Quotas).

Parameters
NameDescription
updateFunctionAsyncFunction<T>

The function to execute within the transaction context.

transactionOptionsTransactionOptions
Returns
TypeDescription
ApiFuture<T>

An ApiFuture that will be resolved with the result from updateFunction.

<T>runTransaction(Transaction.Function<T> updateFunction)

public abstract ApiFuture<T> <T>runTransaction(Transaction.Function<T> updateFunction)

Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, the updateFunction will be retried. If it fails to commit after 5 attempts, the transaction will fail.

Parameter
NameDescription
updateFunctionFunction<T>

The function to execute within the transaction context.

Returns
TypeDescription
ApiFuture<T>

An ApiFuture that will be resolved with the result from updateFunction.

<T>runTransaction(Transaction.Function<T> updateFunction, TransactionOptions transactionOptions)

public abstract ApiFuture<T> <T>runTransaction(Transaction.Function<T> updateFunction, TransactionOptions transactionOptions)

Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, the updateFunction will be retried. If it fails to commit after the maxmimum number of attemps specified in transactionOptions, the transaction will fail.

Parameters
NameDescription
updateFunctionFunction<T>

The function to execute within the transaction context.

transactionOptionsTransactionOptions
Returns
TypeDescription
ApiFuture<T>

An ApiFuture that will be resolved with the result from updateFunction.

batch()

public abstract WriteBatch batch()

Gets a Firestore WriteBatch instance that can be used to combine multiple writes.

Returns
TypeDescription
WriteBatch

A WriteBatch that operates on this Firestore client.

bulkWriter()

public abstract BulkWriter bulkWriter()

Creates a BulkWriter instance, used for performing multiple writes in parallel. Gradually ramps up writes as specified by the 500/50/5 rule. See Also: <a href=https://cloud.google.com/firestore/docs/best-practices#ramping_up_traffic>Ramping up traffic

Returns
TypeDescription
BulkWriter

bulkWriter(BulkWriterOptions options)

public abstract BulkWriter bulkWriter(BulkWriterOptions options)

Creates a BulkWriter instance, used for performing multiple writes in parallel. Gradually ramps up writes as specified by the 500/50/5 rule unless otherwise configured by a BulkWriterOptions object. See Also: <a href=https://cloud.google.com/firestore/docs/best-practices#ramping_up_traffic>Ramping up traffic

Parameter
NameDescription
optionsBulkWriterOptions

An options object to configure BulkWriter.

Returns
TypeDescription
BulkWriter

bundleBuilder()

public abstract FirestoreBundle.Builder bundleBuilder()

Returns a FirestoreBundle.Builder FirestoreBundle.Builder instance using an automatically generated bundle ID. When loaded on clients, client SDKs use the bundle ID and the timestamp associated with the built bundle to tell if it has been loaded already.

Returns
TypeDescription
FirestoreBundle.Builder

bundleBuilder(String bundleId)

public abstract FirestoreBundle.Builder bundleBuilder(String bundleId)

Returns a FirestoreBundle.Builder FirestoreBundle.Builder instance for the given bundle ID.

Parameter
NameDescription
bundleIdString

The ID of the bundle. When loaded on clients, client SDKs use this id and the timestamp associated with the built bundle to tell if it has been loaded already.

Returns
TypeDescription
FirestoreBundle.Builder

close()

public abstract void close()

Closes the gRPC channels associated with this instance and frees up their resources. This method blocks until all channels are closed. Once this method is called, this Firestore client is no longer usable.

Exceptions
TypeDescription
Exception

collection(String path)

public abstract CollectionReference collection(String path)

Gets a CollectionReference that refers to the collection at the specified path.

Parameter
NameDescription
pathString

A slash-separated path to a collection.

Returns
TypeDescription
CollectionReference

The CollectionReference instance.

collectionGroup(String collectionId)

public abstract CollectionGroup collectionGroup(String collectionId)

Creates and returns a new CollectionGroup that includes all documents in the database that are contained in a collection or subcollection with the given @code{collectionId}.

Parameter
NameDescription
collectionIdString

Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash.

Returns
TypeDescription
CollectionGroup

The created Query.

document(String path)

public abstract DocumentReference document(String path)

Gets a DocumentReference that refers to the document at the specified path.

Parameter
NameDescription
pathString

A slash-separated path to a document.

Returns
TypeDescription
DocumentReference

The DocumentReference instance.

getAll(DocumentReference[] documentReferences)

public abstract ApiFuture<List<DocumentSnapshot>> getAll(DocumentReference[] documentReferences)

Retrieves multiple documents from Firestore.

Parameter
NameDescription
documentReferencesDocumentReference[]

List of Document References to fetch.

Returns
TypeDescription
ApiFuture<List<DocumentSnapshot>>

getAll(DocumentReference[] documentReferences, FieldMask fieldMask)

public abstract ApiFuture<List<DocumentSnapshot>> getAll(DocumentReference[] documentReferences, FieldMask fieldMask)

Retrieves multiple documents from Firestore, while optionally applying a field mask to reduce the amount of data transmitted.

Parameters
NameDescription
documentReferencesDocumentReference[]

Array with Document References to fetch.

fieldMaskFieldMask

If set, specifies the subset of fields to return.

Returns
TypeDescription
ApiFuture<List<DocumentSnapshot>>

getAll(DocumentReference[] documentReferences, FieldMask fieldMask, ApiStreamObserver<DocumentSnapshot> responseObserver)

public abstract void getAll(DocumentReference[] documentReferences, FieldMask fieldMask, ApiStreamObserver<DocumentSnapshot> responseObserver)

Retrieves multiple documents from Firestore while optionally applying a field mask to reduce the amount of data transmitted. Returned documents will be out of order.

Parameters
NameDescription
documentReferencesDocumentReference[]

Array with Document References to fetch.

fieldMaskFieldMask

If not null, specifies the subset of fields to return.

responseObserverApiStreamObserver<DocumentSnapshot>

The observer to be notified when DocumentSnapshot details arrive.

listCollections()

public abstract Iterable<CollectionReference> listCollections()

Fetches the root collections that are associated with this Firestore database.

Returns
TypeDescription
Iterable<CollectionReference>

An Iterable that can be used to fetch all collections.

recursiveDelete(CollectionReference reference)

public abstract ApiFuture<Void> recursiveDelete(CollectionReference reference)

Recursively deletes all documents and subcollections at and under the specified level.

If any delete fails, the ApiFuture contains an error with an error message containing the number of failed deletes and the stack trace of the last failed delete. The provided reference is deleted regardless of whether all deletes succeeded.

recursiveDelete() uses a BulkWriter instance with default settings to perform the deletes. To customize throttling rates or add success/error callbacks, pass in a custom BulkWriter instance.

Parameter
NameDescription
referenceCollectionReference

The reference of the collection to delete.

Returns
TypeDescription
ApiFuture<Void>

An ApiFuture that completes when all deletes have been performed. The future fails with an error if any of the deletes fail.

recursiveDelete(CollectionReference reference, BulkWriter bulkWriter)

public abstract ApiFuture<Void> recursiveDelete(CollectionReference reference, BulkWriter bulkWriter)

Recursively deletes all documents and subcollections at and under the specified level.

If any delete fails, the ApiFuture contains an error with an error message containing the number of failed deletes and the stack trace of the last failed delete. The provided reference is deleted regardless of whether all deletes succeeded.

recursiveDelete() uses a BulkWriter instance with default settings to perform the deletes. To customize throttling rates or add success/error callbacks, pass in a custom BulkWriter instance.

Parameters
NameDescription
referenceCollectionReference

The reference of the collection to delete.

bulkWriterBulkWriter

A custom BulkWriter instance used to perform the deletes.

Returns
TypeDescription
ApiFuture<Void>

An ApiFuture that completes when all deletes have been performed. The future fails with an error if any of the deletes fail.

recursiveDelete(DocumentReference reference)

public abstract ApiFuture<Void> recursiveDelete(DocumentReference reference)

Recursively deletes all documents and subcollections at and under the specified level.

If any delete fails, the ApiFuture contains an error with an error message containing the number of failed deletes and the stack trace of the last failed delete. The provided reference is deleted regardless of whether all deletes succeeded.

recursiveDelete() uses a BulkWriter instance with default settings to perform the deletes. To customize throttling rates or add success/error callbacks, pass in a custom BulkWriter instance.

Parameter
NameDescription
referenceDocumentReference

The reference of the document to delete.

Returns
TypeDescription
ApiFuture<Void>

An ApiFuture that completes when all deletes have been performed. The future fails with an error if any of the deletes fail.

recursiveDelete(DocumentReference reference, BulkWriter bulkWriter)

public abstract ApiFuture<Void> recursiveDelete(DocumentReference reference, BulkWriter bulkWriter)

Recursively deletes all documents and subcollections at and under the specified level.

If any delete fails, the ApiFuture contains an error with an error message containing the number of failed deletes and the stack trace of the last failed delete. The provided reference is deleted regardless of whether all deletes succeeded.

recursiveDelete() uses a BulkWriter instance with default settings to perform the deletes. To customize throttling rates or add success/error callbacks, pass in a custom BulkWriter instance.

Parameters
NameDescription
referenceDocumentReference

The reference of the document to delete.

bulkWriterBulkWriter

A custom BulkWriter instance used to perform the deletes.

Returns
TypeDescription
ApiFuture<Void>

An ApiFuture that completes when all deletes have been performed. The future fails with an error if any of the deletes fail.

shutdown()

public abstract void shutdown()

Initiates an orderly shutdown in which previously submitted work is finished, but no new work will be accepted.

shutdownNow()

public abstract void shutdownNow()

Attempts to stop all actively executing work and halts the processing of waiting work.