0

I'm trying to write a cloud function using node.js and I'm getting this error:

TypeError: Cannot read property 'user_id' of undefined at exports.FindRoom.functions.database.ref.onWrite (/user_code/index.js:299:39) at Object. (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)

From this function:

exports.FindRoom = functions.database.ref(`/FindRoom/{user_id}`).onWrite((event) =>{ var user_id = event.params.user_id; console.log("user_id",user_id); var user_question = event.data.val(); console.log("user_question",user_question); if (!event.data.val()) { return console.log('A game room was deleted from database',user_id); } 

It's a first time I'm using Firebase and Cloud Functions, and the function worked well before I made npm update for Firebase. After update I'm getting this error and could not find a solution.

1

2 Answers 2

1

The path string needs to be a literal string, not a template. So replace the backticks (`) with regular (single or double) quotes:

exports.FindRoom = functions.database.ref("/FindRoom/{user_id}").onWrite(... 
Sign up to request clarification or add additional context in comments.

Comments

0

I am not 100% sure but Firebase just got updated to its v1 and it changes stuff about database. I received an email this morning. You can see the changes over here.

Hope it helps!

2 Comments

It helps a lot. Thank you!
@AlexL I'm glaed it helped :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.