How to undo the change in Firestore? - firebase

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

Related

Whats the preferred way to backup an entire firestore database automatically on a schedule that would allow for a manual restore

New to Firestore, really enjoy using it but the one issue I have is that I can't see an obvious way to backup the entire database for a given project, the idea being that if anything goes wrong I can overwrite the nodes with the backup.
In the Realtime Database, you can back up your data by simply exporting it from the Firebase Console. However, for Firestore, you have to use Google Cloud Console. Here are the docs:
https://firebase.google.com/docs/firestore/manage-data/export-import
If you need to schedule that operation, it's recommended to use Cloud Functions for Firebase as explained here:
https://cloud.google.com/firestore/docs/solutions/schedule-export

Testing firestore with disableNetwork [duplicate]

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.

Where should the code reside to update Firestore?

If I have a Firestore database that I want to constantly be updating (and listeners in my code to constantly be responding to backend updates), should the code that's responsible for updating the database belong in the android app that will be available for download to other people? Or is it supposed to be somewhere else?
For example, the code for creating a document with user info within the collection "Users" belongs in every instance of the app that I publish, because I want every user using my app to be able to write their login info to the Firestore database after they register through Firebase Auth.
But if I have a different collection of data that I want to be available to all users using my app, and I want to be updating that data constantly, should I be updating it with code that goes in with my production level app, or should that be happening somewhere else? And if it should be happening somewhere else, where should that be/how should that be done?
I'd appreciate any help with this!
Never mind, I found the answer to my own question. Firebase provides users with Cloud Functions, which can run on the server-side to respond to new data events.
You might also be interested in Realtime Database, it will mean you don't have to write any of these listeners to the data and it does it all automatically. Check it out here;
https://firebase.google.com/docs/database/rtdb-vs-firestore

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.

Sync SQLite data with FireBase automatically

Actually my data is in GB so every time manually sync for updating is not make sense. So I want to sync my SQLite database with Firebase database automatically, either it may be offline or online. And I want syncing from both ways. "FB to SQLite" and "SQLite to FB".
Is it in Android ? if you already have functionality to manual sync the data, then should not be a problem to automate it. You can call same sync functionality through a service, which in turn will use CountDownTimer. CountDownTimer as per preference can be called every couple of minutes or hourly.
There is no built-in functionality for Firebase to synchronize with SQlite, nor built-in functionality in SQlite to synchronize with Firebase.
But since both have an API, you can write code to do the synchronization for you.
Actually firebase use persistency to work while offline but dynamically can get only last event whatever it is. So have to write our own Sync for that.

Resources