Testing firestore with disableNetwork [duplicate] - firebase

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!

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.

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.

Related

How to undo the change in Firestore?

I am using Firestore NoSQL for iOS application. While debugging, I occasionally executed setData instead of updateData, what led to lost of all the user data (one user).
Is there a way to reverse back the changes?
How to do Versioning for Firestore, for similar cases, so there's a way to cancel/ backup. I don't quite know, but I've read that it supposed to be Versioning.
There is no option to undo changes in Firestore. I'd recommend creating a new database (project) for testing purposes so you don't accidentally write on the main database. For now if it's just a single user then I'd recommend manually add that back.
Unlike realtime database, you can only have one Firestore instance per project at the moment so you may have to create a new project but I think that'll be safe to prevent such accidental writes :)
"You can use the Cloud Firestore managed export and import service to recover from accidental deletion of data and to export data for offline processing."
That's what I've found for now: https://firebase.google.com/docs/firestore/manage-data/export-import

Force Firestore Database to Cache Database

Is it possible to force the Firestore Database to cache an entire database offline?
Currently, Firestore caches what has already been accessed in the app. I want to use data offline that the user may not have accessed before going offline.
I'm using Flutter for the app.
The only way to locally cache data from Firestore is to actually query for that data. You will need to execute queries for all the documents you wish to cache. There is currently no alternative to this.

AngularFIre Firebase saving data locally?

I have an app that displays a list of items. Here is what I am doing.
When the app first loads I am making an HTTP request to get the list from the firebase database.
once the list is received the list is stored locally on localStorage for future use.
On future app loads, the list is loaded from localStorage to prevent unnecessary http calls
I am doing the above programmatically, i.e, saving data to localStorage and check for new data and getting it etc.
Does firebase provide any other way to the same?
There is no built-in support for cross page-reload persistence in the JavaScript SDK for the Firebase Realtime Database. Somebody is working on such functionality in the open-source repository, but no release was made with it yet.
If you need this functionality, I highly recommend looking into using Cloud Firestore. In addition to many other benefits, it supports cross page-reload persistence.

how to enable persistance storage in firestore?

I am working on react-native with firestore and creating an offline application. The data should be stored in firestore when there is an healthy internet connection. If not, it should be stored in cache.
In firestore, there is an Enable offline data where the data can be stored offline. But, I didn't understand what and where exactly I've to write into that.
So anyone can help me out?
Thanks in advance
in your firebase file immediately after
firebase.initializeApp(firebbaseConfig)
firebase.firestore()
.enable persistence()
.catch(err => console.log(err)
The documentation for offline persistence states:
To use offline persistence, you don't need to make any changes to the
code that you use to access Cloud Firestore data. With offline
persistence enabled, the Cloud Firestore client library automatically
manages online and offline data access and synchronizes local data
when the device is back online.
So, you don't have to do anything to take this default behavior.
Firestore maintains copy of data locally, so even it writes data in offline and fetch it.
If you want to enable firestore persistence in your react native app, just copy paste the code from documentation to App.js, I am using the same and it is working fine.

How to clear Firestore persistence data?

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!
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.
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.

Resources