Firebase. Firestore. FirebaseFirestore
Represents a CloudFirestore database and is the entry point for all CloudFirestore operations.
Summary
Properties | |
|---|---|
App | Returns the FirebaseApp instance to which thisFirebaseFirestore belongs. |
DefaultInstance | staticFirebaseFirestore |
LogLevel | staticLogLevelSets the log verbosity of allFirestore instances. |
Settings | The settings of this FirebaseFirestore object. |
Public static functions | |
|---|---|
GetInstance(FirebaseApp app) | |
GetInstance(string database) | |
GetInstance(FirebaseApp app, string database) | |
Public functions | |
|---|---|
ClearPersistenceAsync() | TaskClears the persistent storage. |
Collection(string path) | Creates a localCollectionReference for the given path, which must include an odd number of slash-separated identifiers. |
CollectionGroup(string collectionId) | Creates and returns a newQuery that includes all documents in the database that are contained in a collection or subcollection with the given collection ID. |
DisableNetworkAsync() | TaskDisables network access for this instance. |
Document(string path) | Creates a localDocumentReference for the given path, which must include an even number of slash-separated identifiers. |
EnableNetworkAsync() | TaskRe-enables network usage for this instance after a prior call toFirebaseFirestore.DisableNetworkAsync. |
GetNamedQueryAsync(string queryName) | Task<Query > |
ListenForSnapshotsInSync(Action callback) | Attaches a listener for a snapshots-in-sync event. |
LoadBundleAsync(string bundleData) | Task<LoadBundleTaskProgress >Loads aFirestore bundle into the local cache. |
LoadBundleAsync(string bundleData, System.EventHandler<LoadBundleTaskProgress > progressHandler) | Task<LoadBundleTaskProgress >Loads aFirestore bundle into the local cache, taking an System.EventHandler to monitor loading progress. |
LoadBundleAsync(byte[] bundleData) | Task<LoadBundleTaskProgress >Loads aFirestore bundle into the local cache. |
LoadBundleAsync(byte[] bundleData, System.EventHandler<LoadBundleTaskProgress > progressHandler) | Task<LoadBundleTaskProgress >Loads aFirestore bundle into the local cache, taking an System.EventHandler to monitor loading progress. |
RunTransactionAsync(Func<Transaction, Task > callback) | TaskRuns a transaction asynchronously, with an asynchronous callback that doesn't return a value. |
RunTransactionAsync(TransactionOptions options, Func<Transaction, Task > callback) | TaskRuns a transaction asynchronously, with an asynchronous callback that doesn't return a value. |
RunTransactionAsync< T >(Func<Transaction, Task< T >> callback) | Task< T >Runs a transaction asynchronously, with an asynchronous callback that returns a value. |
RunTransactionAsync< T >(TransactionOptions options, Func<Transaction, Task< T >> callback) | Task< T >Runs a transaction asynchronously, with an asynchronous callback that returns a value. |
StartBatch() | Creates a write batch, which can be used to commit multiple mutations atomically. |
TerminateAsync() | TaskTerminates this FirebaseFirestore instance. |
WaitForPendingWritesAsync() | TaskWaits until all currently pending writes for the active user have been acknowledged by the backend. |
Properties
DefaultInstance
staticFirebaseFirestoreDefaultInstance
Gets the instance ofFirebaseFirestore for the defaultFirebaseApp with the defaultdatabase name.
AFirebaseFirestore instance.
LogLevel
staticLogLevelLogLevel
Settings
FirebaseFirestoreSettingsSettings
The settings of thisFirebaseFirestore object.
To change the settings used by thisFirebaseFirestore instance, simply change the values of the properties on thisFirebaseFirestoreSettings object.
Invoking any non-static method on thisFirebaseFirestore instance will "lockin" the settings. No changes are allowed to be made to the settings once they are locked in. Attempting to do so will result in an exception being thrown by the property setter.
Public static functions
GetInstance
FirebaseFirestoreGetInstance(FirebaseAppapp)
Gets an instance ofFirebaseFirestore for a specificFirebaseApp with the defaultdatabase name.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A FirebaseFirestore instance. |
GetInstance
FirebaseFirestoreGetInstance(stringdatabase)
Gets an instance ofFirebaseFirestore for the defaultFirebaseApp with a spesificdatabase name.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A FirebaseFirestore instance. |
GetInstance
FirebaseFirestoreGetInstance(FirebaseAppapp,stringdatabase)
Gets an instance ofFirebaseFirestore for a specificFirebaseApp with a spesificdatabase name.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Public functions
ClearPersistenceAsync
TaskClearPersistenceAsync()
Clears the persistent storage.
This includes pending writes and cached documents.
Must be called while theFirestore instance is not started (after the app is shut down or when the app is first initialized). On startup, this method must be called before other methods (other than getting or settingFirebaseFirestoreSettings). If theFirestore instance is still running, the task will complete with an error code ofFailedPrecondition.
Note:ClearPersistenceAsync() is primarily intended to help write reliable tests that useFirestore. It uses the most efficient mechanism possible for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cache data in between user sessions we strongly recommend not to enable persistence in the first place.
| Details | |
|---|---|
| Returns | A Task which completes when the clear persistence operation has completed. |
Collection
CollectionReferenceCollection(stringpath)
Creates a localCollectionReference for the given path, which must include an odd number of slash-separated identifiers.
This does not perform any remote operations.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A collection reference. |
CollectionGroup
QueryCollectionGroup(stringcollectionId)
Creates and returns a newQuery that includes all documents in the database that are contained in a collection or subcollection with the given collection ID.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | The createdQuery. |
DisableNetworkAsync
TaskDisableNetworkAsync()
Disables network access for this instance.
While the network is disabled, any snapshot listeners orGetSnapshotAsync calls will return results from cache, and any write operations will be queued until network usage is re-enabled via a call toFirebaseFirestore.EnableNetworkAsync.
| Details | |
|---|---|
| Returns | A task which completes once networking is disabled. |
Document
DocumentReferenceDocument(stringpath)
Creates a localDocumentReference for the given path, which must include an even number of slash-separated identifiers.
This does not perform any remote operations.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A document reference. |
EnableNetworkAsync
TaskEnableNetworkAsync()
Re-enables network usage for this instance after a prior call toFirebaseFirestore.DisableNetworkAsync.
| Details | |
|---|---|
| Returns | A task which completes once networking is enabled. |
GetNamedQueryAsync
Task<Query>GetNamedQueryAsync(stringqueryName)
Reads aFirestoreQuery from the local cache, identified by the given name.
Named queries are packaged into bundles on the server side (along with the resulting documents) and loaded into local cache usingFirebaseFirestore.LoadBundleAsync(string). Once in the local cache, you can use this method to extract a query by name.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A task that is completed with the query associated with the given name. The result of the returned task is set to null if no queries can be found. |
ListenForSnapshotsInSync
ListenerRegistrationListenForSnapshotsInSync(Actioncallback)
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. UseSnapshotMetadata in the individual listeners to determine if a snapshot is from the cache or the server.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A registration object that can be used to remove the listener. |
LoadBundleAsync
Task<LoadBundleTaskProgress>LoadBundleAsync(stringbundleData)
Loads aFirestore bundle into the local cache.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A task that is completed when the loading is completed. The result of the task then contains the final progress of the loading operation. |
LoadBundleAsync
Task<LoadBundleTaskProgress>LoadBundleAsync(stringbundleData,System.EventHandler<LoadBundleTaskProgress>progressHandler)
Loads aFirestore bundle into the local cache, taking an System.EventHandler to monitor loading progress.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A task that is completed when the loading is completed. The result of the task then contains the final progress of the loading operation. |
LoadBundleAsync
Task<LoadBundleTaskProgress>LoadBundleAsync(byte[]bundleData)
Loads aFirestore bundle into the local cache.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A task that is completed when the loading is completed. The result of the task then contains the final progress of the loading operation. |
LoadBundleAsync
Task<LoadBundleTaskProgress>LoadBundleAsync(byte[]bundleData,System.EventHandler<LoadBundleTaskProgress>progressHandler)
Loads aFirestore bundle into the local cache, taking an System.EventHandler to monitor loading progress.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A task that is completed when the loading is completed. The result of the task then contains the final progress of the loading operation. |
RunTransactionAsync
TaskRunTransactionAsync(Func<Transaction,Task>callback)
Runs a transaction asynchronously, with an asynchronous callback that doesn't return a value.
The specified callback is executed for a newly-created transaction.
RunTransactionAsync executes the given callback on the main thread and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, thecallback will be retried. If it fails to commit after 5 attempts, the transaction will fail.
The maximum number of writes allowed in a single transaction is 500, but note that each usage ofFieldValue.ServerTimestamp,FieldValue.ArrayUnion,FieldValue.ArrayRemove, orFieldValue.Increment inside a transaction counts as an additional write.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A task which completes when the transaction has committed. |
RunTransactionAsync
TaskRunTransactionAsync(TransactionOptionsoptions,Func<Transaction,Task>callback)
Runs a transaction asynchronously, with an asynchronous callback that doesn't return a value.
The specified callback is executed for a newly-created transaction.
RunTransactionAsync executes the given callback on the main thread and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, thecallback will be retried. If it fails to commit after the maximum number of attempts specified in the givenTransactionOptions object, the transaction will fail.
The maximum number of writes allowed in a single transaction is 500, but note that each usage ofFieldValue.ServerTimestamp,FieldValue.ArrayUnion,FieldValue.ArrayRemove, orFieldValue.Increment inside a transaction counts as an additional write.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A task which completes when the transaction has committed. |
RunTransactionAsync< T >
Task<T>RunTransactionAsync<T>(Func<Transaction,Task<T>>callback)
Runs a transaction asynchronously, with an asynchronous callback that returns a value.
The specified callback is executed for a newly-created transaction.
RunTransactionAsync executes the given callback on the main thread and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, thecallback will be retried. If it fails to commit after 5 attempts, the transaction will fail.
The maximum number of writes allowed in a single transaction is 500, but note that each usage ofFieldValue.ServerTimestamp,FieldValue.ArrayUnion,FieldValue.ArrayRemove, orFieldValue.Increment inside a transaction counts as an additional write.
| Details | |||
|---|---|---|---|
| Template Parameters |
| ||
| Parameters |
| ||
| Returns | A task which completes when the transaction has committed. The result of the task then contains the result of the callback. |
RunTransactionAsync< T >
Task<T>RunTransactionAsync<T>(TransactionOptionsoptions,Func<Transaction,Task<T>>callback)
Runs a transaction asynchronously, with an asynchronous callback that returns a value.
The specified callback is executed for a newly-created transaction.
RunTransactionAsync executes the given callback on the main thread and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, thecallback will be retried. If it fails to commit after the maximum number of attempts specified in the givenTransactionOptions object, the transaction will fail.
The maximum number of writes allowed in a single transaction is 500, but note that each usage ofFieldValue.ServerTimestamp,FieldValue.ArrayUnion,FieldValue.ArrayRemove, orFieldValue.Increment inside a transaction counts as an additional write.
| Details | |||||
|---|---|---|---|---|---|
| Template Parameters |
| ||||
| Parameters |
| ||||
| Returns | A task which completes when the transaction has committed. The result of the task then contains the result of the callback. |
StartBatch
WriteBatchStartBatch()
Creates a write batch, which can be used to commit multiple mutations atomically.
| Details | |
|---|---|
| Returns | A write batch for this database. |
TerminateAsync
TaskTerminateAsync()
Terminates thisFirebaseFirestore instance.
After callingTerminate(), only theClearPersistenceAsync() method may be used. Calling any other method will result in an error.
To restart after termination, simply create a new instance ofFirebaseFirestore withGetInstance() methods.
Terminate() does not cancel any pending writes, and any tasks that are awaiting a response from the server will not be resolved. The next time you start this instance, it will resume attempting to send these writes to the server.
Note: under normal circumstances, callingTerminate() is not required. This method is useful only when you want to force this instance to release all of its resources or in combination withClearPersistenceAsync to ensure that all local state is destroyed between test runs.
| Details | |
|---|---|
| Returns | A Task which completes when the instance has been successfully terminated. |
WaitForPendingWritesAsync
TaskWaitForPendingWritesAsync()
Waits until all currently pending writes for the active user have been acknowledged by the backend.
The returned Task completes immediately if there are no outstanding writes. Otherwise, the Task waits for all previously issued writes (including those written in a previous app session), but it does not wait for writes that were added after the method is called. If you wish to wait for additional writes, you have to callWaitForPendingWritesAsync() again.
Any outstandingWaitForPendingWritesAsync() Tasks are cancelled during user changes.
| Details | |
|---|---|
| Returns | A Task which completes when all currently pending writes have been acknowledged by the backend. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-07-20 UTC.