I am using Firebase spark FREE plan and want to know what if I want to reset my data again to 0 Byte and clear all storage from Real Time database? for example if I want to reset all data and make it 0 again as it was when I made project, what steps to follow and is it possible?
You can delete all data the database in either the Firebase console, or through its API by calling remove on the root.
If you've done that and there still are some bytes showing in the console screenshots, those might be some leftover metadata for the database. If that is the case, there's nothing you can do about it, and you only have 1GM - 515 bytes that you can still add to it on the free plan.
Related
I am developing a chrome extension for the new tab page and I am trying to find the right DB for the project. The only question that is keeping me from using Firebase Firestore is to know how the DB handles reads.
Basically, every time the user opens a new tab page I will need to fetch around 3000 (very small) documents (hopefully from cache). My issue is that since opening a new tab page is done so frequently I will be charged an absurd amount of reads because firestore is always reading 3K documents.
My question is, is Firestore smart enough to tell that in the DB data has not changed and the client should only read from the cache?
I read all about offline persistence but this question is still lingering!
Thank you for any help!
When you start a listener you read first from the cache and then from the server. The cache persistance here explains how it behaves but considering only that the listener is in the listening mode. Even then after a 30 in offline you would be charged for a full read.
I would recommend you to read this. To manage your cache on your own to awoid to much reads as you are reading a large amount of data.
Every time I close my application it has to load the data from the firebase again. Is there any way for it to already open with the last data fetched?
If you enable disk persistence, the Firebase client will write any data it sees to a local disk cache. This means that when you restart the app when there's no connectivity, the same data that you saw before is available offline on your app.
For more info, see the Firebase documentation on disk persistence and the call to enable it from Flutter.
You should explain a bit more, so we understand your use case. Anyways, i'll try to answer with what I have understood.
You can use sqflite package to cache the data, i.e. it will be stored to the local storage. Get started: https://pub.dev/packages/sqflite
It will be fairly complex, even unnecessary if the size of your data is small.
If you have huge amount of data that doesn't change frequently, then go for it.
So how it will work is like this:
First you'll check whether the data has changed in Firestore or not.
Case 1: If it didn't then you'll display data from your local sqflite db.
Case 2: If it did change, then, you'll display data from Firestore, and at the same time update your local db with the new data.
Again, this is very superfluous if your data size is be small/it changes very frequently.
In my app I have a lot of PNGs, about 150 mb. First time my user will download them all, but then the user should only download new/deleted/modified PNGs, not the ones that stay the same. How can I use Firebase/Firestore for this?
First, I decided to use SQLite as offline database, because I read that firebase will charge for offline reads. Then I read that when keepSync enabled and setPersistanceEnabled(true), Firebase will download my entire 150 mb database every time the app starts.
The problem is; my app is a mainly offline app. I don't to pay for offline usage, and I expect firebase to be smart and sync "on demand" and sync only "new stuff". To be clear, the user will only display my PNGs, not modify them. So data flow in my sample is one way; from online db to local device.
I hope I made it clear what I expect. Feel free to recommend other tools. I can change the order of my PNGs, add new PNGs, delete them, modify them, but in the end most will stay same and I don't want to be charged for PNGs that are same for years.
Sorry for long post, but I couldn't see any solid answer despite a lot of questions.
Update: Editing the question title/body based on the suggestion.
Firebase store makes everything that is publicly readable also publicly accessible to the browser with a script, so nothing stops any user from just saying db.get('collection') and saving all the data as theirs.
In more traditional db setup where an app's frontend is pulling data from backend, and the user would have to at least go through the extra trouble of tweaking the UI and then scraping the front end to pull more-and-more data (think Twitter load more button).
My question was whether it was possible to limit users from accessing the entire database in a click, while also keeping the data publicly available.
Old:
From what I understand, any user who can see data coming out of a Firebase datastore can also run a query to extract all of that data. That is not desirable when data itself is of any value, and yet Firebase is such an easy to use tool, it's great for pretty much everything else.
Is there a way, or a best practice, for how to structure the data or access rules s.t. users see the data, but can't just run a script to download all of it entirely?
Thanks!
Kato once implemented a simplistic rate limit for writes in Realtime Database security rules: Firebase rate limiting in security rules?. Something similar could be possible in Cloud Firestore rules. But this approach won't work for reads, since you can't update the timestamp at the same time the read is performed.
You can however limit what queries a user can perform on your database. For example, to limit them to reading 50 documents at a time:
allow list: if request.query.limit <= 50;
My goal is to have a firebase cloud function track the upload of three separate files to the same storage bucket. These uploads are preceded by a write to the real time database which would preferably be the trigger for the cloud function to track the uploads.
The context is a user is adding an item to her shopping cart. The data is written to the RTDB and then a custom 3d model and 2 images are copied into a storage bucket. If any of these files don't successfully upload, I need to know that and conduct a rollback of the 3 files in the storage bucket and also remove the entry in the database. I could handle this client side, but that isn't ideal since usually if the uploads fail, its because the connection with the client has failed.
I haven't been able to find any sort of batch add or transaction-type uploads to firebase storage. Sorry for not having any code to show, but I'm not even really sure how to get started on this. Any suggestions would be much appreciated. Thanks!
There are no transactions that cross products like this. Nor are there any transactions offered by Cloud Storage. You're going to have to check errors and manually undo things previously done. Or, have some job that checks for orphaned data and deletes it later.