Reputation: 2304
I'm trying to access data from firebase cloud function.
I have group of users (like a group chat) and each group has key.
I try to access the group within a cloud function :
admin.database().ref('/GroupUsers/${groupKey}').once('value');
and get the following error:
Error: Firebase.child failed: First argument was an invalid path: "/GroupUsers/${groupKey}". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]" at Error (native) at qd (/user_code/node_modules/firebase-admin/lib/database/database.js:97:59) at W.h.n (/user_code/node_modules/firebase-admin/lib/database/database.js:257:178) at ch.h.gf (/user_code/node_modules/firebase-admin/lib/database/database.js:218:663) at exports.startContest.functions.database.ref.onUpdate.event (/user_code/index.js:21:49) at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27) at next (native) at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71 at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
where group key is input to onUpdate Firebase' cloud function
Thank u in advace
Upvotes: 0
Views: 145
Reputation: 317467
If you want to insert a variable inside a string in JavaScript, use backticks to delimit the string (you're using single quotes).
admin.database().ref(`/GroupUsers/${groupKey}`).once('value');
Upvotes: 1