Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Firestore persistence data?

Tags:

My iOS app's firestore cache seems to have got out of sync with Firestore. As a result I've had to disable persistence. Is there anyway to reset the cache? And is there a way to make sure it's constantly in sync? All I did was delete documents from the database!

like image 596
Tometoyou Avatar asked Feb 22 '18 14:02

Tometoyou


People also ask

How do I clear my firestore data?

To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them. If you have larger collections, you may want to delete the documents in smaller batches to avoid out-of-memory errors.

What is firestore persistence?

Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.

How do I delete multiple files from firestore cloud?

To delete multiple documents, you can do a single batched write. The WriteBatch class has a delete() method for this purpose. The performance to between a single BatchedWrite and multiple DocumentReference.


2 Answers

There is now a feature in the API for clearing persistence. It is not recommended for anything but tests, but you can use

firebase.firestore().clearPersistence().catch(error => {
  console.error('Could not enable persistence:', error.code);
})

It must run before the Firestore database is used.

like image 136
Ryan Taylor Avatar answered Oct 05 '22 14:10

Ryan Taylor


There's no API for manipulating the local cache in any way. The Firestore SDK chooses what to store based on queries that you perform.

On Android, users can manually clear the local data for an app without uninstalling it. This will remove all the data locally stored by the app.

If you have a specific use case, please feel free to file a feature request.

like image 26
Doug Stevenson Avatar answered Oct 05 '22 14:10

Doug Stevenson