13

I want to use onCreate method instead of onWrite for the sake of efficiency but I face that error:

functions.database.ref(...).onCreate is not a function.

However, there seems to be a function as mentioned in the doc https://firebase.google.com/docs/reference/functions/functions.database.RefBuilder#onCreate
My code starts as follows:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.manager = functions.database.ref('some_ref')
    .onCreate(event =>{


I am looking forward to your helps.
Thanks in advance.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Ziya ERKOC
  • 839
  • 7
  • 18
  • a full code snippet will be more efficient to understand the full picture. without it, i would guess that you forgot to require the functions package? – Ben Yitzhaki Jul 09 '17 at 11:43
  • 2
    `onCreate()` is a new feature that was released in the last few days. I'm guessing something in your build config needs to be updated, but I don't know what it is. – Bob Snyder Jul 09 '17 at 14:40
  • Yeah, I have just seen that it was released 2 days ago so i better do some update – Ziya ERKOC Jul 09 '17 at 14:51
  • 7
    Run `npm upgrade` from your functions folder to upgrade your node modules. You need firebase-functions with at least version 0.5.9. – Doug Stevenson Jul 09 '17 at 16:21

1 Answers1

17

Update: In a comment on the question, Firebaser Doug Stevenson indicates that running npm upgrade in the project's functions folder is the simpler way to update to the latest version.


I don't find any documentation for how to update to the latest version of firebase-functions. Following the general guidelines described here, go to your project's functions directory and enter this command:

npm install --save firebase-functions

You can then look in the package.json file to see the versions installed. The new version of firebase-functions that contains the new triggers is 0.5.9

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158