Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Firestore in Cloud Functions

I want to integrate the new Cloud Firestore to my Cloud Functions.

I updated node.js and installed the latest firebase version on my mac.

The Documentation says:

exports.myFunctionName = functions.firestore
  .document('users/marie').onWrite((event) => {
    // ... Your code here
 });

should work. I just copied the code and pasted it into the index.js, like every other realtime database functions. When I deploy the function code ($firebase deploy --only functions), i get this error:

Cannot read property 'document' of undefined
    at Object.<anonymous> (/private/var/folders/zm/wp2415l929s472jv7kzbt3km0000gn/T/fbfn_21520Y4xqAJosBNHe/index.js:196:45)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

Any suggestions/ideas on the problem?

like image 368
bobski Avatar asked Oct 11 '17 19:10

bobski


1 Answers

Try changing your package to:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "firebase-admin": "~5.4.0",
    "firebase-functions": "^0.7.0"
  },
  "private": true
}

And run a update after that in the terminal (npm update).

like image 190
J. Doe Avatar answered Oct 01 '22 23:10

J. Doe