1

It's a simple question, I have seen all these methods addressed in the title in the documentation but all the examples are using onWrite() for triggering database events which then one would have to check to make sure it's not for removing or updating with

exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
    .onWrite(event => {
...
  // Only edit data when it is first created.
      if (event.data.previous.exists()) {
        return;
      }
      // Exit when the data is deleted.
      if (!event.data.exists()) {
        return;
      }
...
});

The only examples with onCreate() for instance, are related to auth events. Is there a reason or am I just being paranoid? Why not just use onCreate() and not bother the check?

1 Answer 1

4

onCreate(), onUpdate() and onDelete() were added in the Firebase SDK for Cloud Functions (v0.5.9) release on 7 July 2017. This is detailed in the release notes:

An updated beta release of the Firebase SDK for Cloud Functions (v0.5.9) is now available. It includes the ability to listen to granular create, update, and delete database events by using the onCreate(), onUpdate(), and onDelete() methods.

Prior to that release, the only database event handler was onWrite(). The documentation has not yet been updated to include examples of the new handlers.

There is no reason not to take advantage of the convenience of the new handlers.

Sign up to request clarification or add additional context in comments.

1 Comment

thxx @Bob. was wondering how come my push is being triggered when im just updating the post. cuz i was using onWrite() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.