Mario Medina
Mario Medina

Reputation: 43

How to abort creation into firebase realtime database from a cloud function?

I'm creating an application that uses two step object creation into firebase realtime database.

What I want is that on a cloud function that catches onCreate event, if some rules are not complete, then the create action be stopped.

Is there a way to do that? Or I need to remove the node instead of reject the creation?

Thank you!

Upvotes: 0

Views: 282

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317467

You might want to consider a command-response model for database writes. Instead of writing directly into the database and expecting that a function cancel the write, push a "command" object into the database that describes what you want to do, at a different location, and have a function respond to that command to determine what should actually be done. Your function can then determine whether or not to commit a final write if the conditions are OK.

I gave a talk at Google I/O 2017 that outlines this strategy with respect to a multi-player turn based game that intercepts all move requests to determine if they're valid before committing them to the game. The part about command-response starts here.

Upvotes: 1

Frank van Puffelen
Frank van Puffelen

Reputation: 598817

There currently is no way to reschedule a trigger. So indeed, you'll either have to create a new node or trigger a re-check in some other way, e.g. a regular cron trigger to clean up the previously unhandled nodes (blog, video).

Upvotes: 0

Related Questions