FirebaseFirestore

public class FirebaseFirestore extends Object

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

Subclassing Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Public Method Summary

WriteBatch
batch()
Creates a write batch, used for performing multiple writes as a single atomic operation.
CollectionReference
collection(String collectionPath)
Gets a CollectionReference instance that refers to the collection at the specified path within the database.
Task<Void>
disableNetwork()
Disables network access for this instance.
DocumentReference
document(String documentPath)
Gets a `DocumentReference` instance that refers to the document at the specified path within the database.
Task<Void>
enableNetwork()
Re-enables network usage for this instance after a prior call to disableNetwork().
FirebaseApp
getApp()
Returns the FirebaseApp instance to which this FirebaseFirestore belongs.
FirebaseFirestoreSettings
getFirestoreSettings()
Returns the settings used by this FirebaseFirestore object.
static FirebaseFirestore
static FirebaseFirestore
<TResult> Task<TResult>
runTransaction(Function<TResult> updateFunction)
Executes the given updateFunction and then attempts to commit the changes applied within the transaction.
void
setFirestoreSettings(FirebaseFirestoreSettings settings)
Sets any custom settings used to configure this FirebaseFirestore object.
static void
setLoggingEnabled(boolean loggingEnabled)
Globally enables / disables Firestore logging for the SDK.

Inherited Method Summary

Public Methods

public WriteBatch batch ()

Creates a write batch, used for performing multiple writes as a single atomic operation.

Returns
  • The created WriteBatch object.

public CollectionReference collection (String collectionPath)

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

Parameters
collectionPath A slash-separated path to a collection.
Returns
  • The CollectionReference instance.

public Task<Void> disableNetwork ()

Disables network access for this instance. While the network is disabled, any snapshot listeners or get() calls will return results from cache, and any write operations will be queued until network usage is re-enabled via a call to enableNetwork().

Returns
  • A Task that will be completed once networking is disabled.

public DocumentReference document (String documentPath)

Gets a `DocumentReference` instance that refers to the document at the specified path within the database.

Parameters
documentPath A slash-separated path to a document.
Returns
  • The DocumentReference instance.

public Task<Void> enableNetwork ()

Re-enables network usage for this instance after a prior call to disableNetwork().

Returns
  • A Task that will be completed once networking is enabled.

public FirebaseApp getApp ()

Returns the FirebaseApp instance to which this FirebaseFirestore belongs.

Returns
  • The FirebaseApp instance to which this FirebaseFirestore belongs.

public FirebaseFirestoreSettings getFirestoreSettings ()

Returns the settings used by this FirebaseFirestore object.

public static FirebaseFirestore getInstance ()

public static FirebaseFirestore getInstance (FirebaseApp app)

public Task<TResult> runTransaction (Function<TResult> 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.

Parameters
updateFunction The function to execute within the transaction context.
Returns
  • The task returned from the updateFunction.

public void setFirestoreSettings (FirebaseFirestoreSettings settings)

Sets any custom settings used to configure this FirebaseFirestore object. This method can only be called before calling any other methods on this object.

public static void setLoggingEnabled (boolean loggingEnabled)

Globally enables / disables Firestore logging for the SDK.

Send feedback about...

Need help? Visit our support page.