Go to console

FirebaseFirestore

public class FirebaseFirestore extends Object

Represents a Cloud Firestore database and is the entry point for all Cloud Firestore operations.

Subclassing Note: Cloud 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

ListenerRegistration
addSnapshotsInSyncListener(Runnable runnable)
Attaches a listener for a snapshots-in-sync event.
ListenerRegistration
addSnapshotsInSyncListener(Executor executor, Runnable runnable)
Attaches a listener for a snapshots-in-sync event.
ListenerRegistration
addSnapshotsInSyncListener(Activity activity, Runnable runnable)
Attaches a listener for a snapshots-in-sync event.
WriteBatch
batch()
Creates a write batch, used for performing multiple writes as a single atomic operation.
Task<Void>
clearPersistence()
Clears the persistent storage, including pending writes and cached documents.
CollectionReference
collection(String collectionPath)
Gets a CollectionReference instance that refers to the collection at the specified path within the database.
Query
collectionGroup(String collectionId)
Creates and returns a new Query that includes all documents in the database that are contained in a collection or subcollection with the given collectionId.
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
Task<Void>
runBatch(WriteBatch.Function batchFunction)
Executes a batchFunction on a newly created WriteBatch and then commits all of the writes made by the batchFunction as a single atomic unit.
<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 Cloud Firestore logging for the SDK.
Task<Void>
terminate()
Terminates this FirebaseFirestore instance.
Task<Void>
waitForPendingWrites()
Waits until all currently pending writes for the active user have been acknowledged by the backend.

Inherited Method Summary

Public Methods

public ListenerRegistration addSnapshotsInSyncListener (Runnable runnable)

Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync event indicates that all listeners affected by a given change have fired, even if a single server-generated change affects multiple listeners.

NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata in the individual listeners to determine if a snapshot is from the cache or the server.

Parameters
runnable A callback to be called every time all snapshot listeners are in sync with each other.
Returns
  • A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotsInSyncListener (Executor executor, Runnable runnable)

Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync event indicates that all listeners affected by a given change have fired, even if a single server-generated change affects multiple listeners.

NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata in the individual listeners to determine if a snapshot is from the cache or the server.

Parameters
executor The executor to use to call the listener.
runnable A callback to be called every time all snapshot listeners are in sync with each other.
Returns
  • A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotsInSyncListener (Activity activity, Runnable runnable)

Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync event indicates that all listeners affected by a given change have fired, even if a single server-generated change affects multiple listeners.

NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata in the individual listeners to determine if a snapshot is from the cache or the server.