Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couple Firebase Firestore and Firebase Storage calls together into a batch?

I'm looking for a best practice on combined/batch calls for Firebase Storage and Firebase Firestore. For example: I need to delete a document from my Firestore which is related to an image in Firebase Storage. Is there a possibility to do this in such a way that when one of the actions fails, the whole transaction is being reverted?

like image 997
Peter Avatar asked Dec 10 '17 16:12

Peter


People also ask

Can you use Firebase and firestore together?

You can use both Firebase Realtime Database and Cloud Firestore in your app, and leverage each database solution's benefits to fit your needs. For example, you might want to leverage Realtime Database's support for presence, as outlined in Build Presence in Cloud Firestore.

What is the difference between Datastore and firestore?

Firestore in Native modeFirestore is the next major version of Datastore and a re-branding of the product. Taking the best of Datastore and the Firebase Realtime Database, Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development.

Is Firebase realtime database faster than firestore?

Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.

What is the maximum documents that are write by per transaction or batch of write in cloud firestore?

Each transaction or batch of writes can write to a maximum of 500 documents.


1 Answers

There is no real atomic/transactional way of doing that however you can use cloud functions to achieve it reliably.

You can delete a document, and use onDelete trigger to delete the actual file in the storage.

So when you can't delete the document, nothing will happen to the file. If you succeed to delete the document, cloud function will be triggered to delete the image.

like image 166
abeyaz Avatar answered Oct 14 '22 11:10

abeyaz