How can i delete from Firebase RealTime Database based on .index Rule? - firebase

Can anyone help me out with Firebase DB rules?
I have searched for solutions but found nothing related to my query.
I want to search the data based on .index (as in FB Rules) and then delete it by Http. delete request
I'm able to fetch the data based on .index and can see it in my app. But how can I delete that from app? While deleting it gives me 400 status code
https://i.stack.imgur.com/kU4I9.jpg
[These are my FB rules]
https://i.stack.imgur.com/uP45I.png

Related

How can I use local cache and only update changed documents using Firestore?

I'm working on a calendar app and I'm currently fetching the data from firestore to populate the calendar. Eventually, there will be a lot of data to be fetched and I'm trying to understand the caching system of Firestore but can't get behind it.
What I ideally want to achieve:
Always use cached data and only update those documents, which are new, edited or deleted.
How would I achieve that?
If you want to force the SDK to read from the cache, you can specify source options when calling get().
If you find yourself doing this everywhere though, it might make sense to consider using another database than Firestore as that is primarily an online, cloud-hosted database that continues to work while you're temporary offline.

how to delete specific firestore document in Source.CACHE?

I can specify the source If I want to get data from firestore, either default, from server or from cache like this:
query.get(Source.CACHE)
say I normally get 50 documents if using the code above.now I want to delete one specific document from that query in cache, so I want to get only 49 documents.
how to do that ? is it possible ?
You don't have direct control over the status of the internal cache maintained by the Firebase SDKs. You can't delete or invalidate specific items.
The cache is completely managed by the SDK. The SDK determines when documents should be added or removed, based on whether or not they are in sync with the server.
You can use the SDK to delete a document, which will remove it from cached results. But that delete will eventually get synchronized with the server, and that's a permanent change.
If you have steps that show that the internal cache is somehow buggy or inconsistent with the contents of the server, then file a bug report with Firebase support that shows now to reproduce the issue.
I want to delete one specific document from that query in cache, so I want to get only 49 documents.
There is no way you can specify that in a delete() operation. If you want to get that behavior, your device should be offline. In that way, Firestore will delete the record from the local cache. But please note, that once you regain the connection, your record will also be deleted from Firebase servers. While online, there is no way you can have a deleted document in the cache and not from Firebase servers.

Does Firebase have a way to limit access to all public data in the security rules?

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;

Rollback on failure of Firebase storage upload

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.

Does Firebase Database offer features like Events, Triggers and Stored Procedures?

I have a question in regards to the capabilities of Firebase in equivalence to MySQL features like:
Events
Triggers
Stored Procedures
In my case I want to migrate off of MySQL to Firebase but I need to know if the usecase can be replicated in Firebase.
My current MySQL DB I have a table that has a column called status which once it gets changed to 'Final' it triggers the execution of a stored procedure to do a calculation on an entire table.
So in other words I would have to be able to add a 'trigger' on the actual firebase data to then perform a 'stored procedure' to calculate something; is this possible with Firebase?!
You now have the capability to use Cloud Functions for Firebase to write code that triggers in response to changes in your Firebase project. There is lots of sample code that illustrates how to respond to writes to a particular location in your database, among many other types of events.

Resources