How to clear Firestore persistence data?

11,861

Solution 1

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.

Solution 2

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.

Share:
11,861
Tometoyou
Author by

Tometoyou

To you, to you, and further up the chimney.

Updated on June 30, 2022

Comments

  • Tometoyou
    Tometoyou about 2 years

    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!

  • Wiingaard
    Wiingaard about 6 years
    I just did the feature request :)
  • Shoaib Bazmi
    Shoaib Bazmi almost 6 years
    Did you find any solution to it?
  • SammyT
    SammyT over 5 years
    I found it goes out of sync if you are performing operations directly in firestore (not from app device). I deleted data in firestore, then installed the app to a new device, and the new device did not receive any data from firestore, clearing the apps data fixed it. I think if you are performing operations directly in firestore, setting persistence enabled to false seems to be required to get the cache in sync again.
  • straya
    straya over 3 years
    Any best-practices surrounding logout and Firestore cache? I imagine it is bound to the Google Account, but if you have a custom system layer providing auth and accounts on top of that (say a web system) then could it be possible to see more than one (web system) user operating with the same cache of data?
  • Ranjeet Kumar yadav
    Ranjeet Kumar yadav almost 3 years
    @Doug Stevenson is there any feature added regarding this in the firestore?