The Firebase functions by Nodejs is not retrieving the results from the data stored in the Cloud Firestore Database. Giving a:
TypeError of Undefined user_id
NodeJS Code
'use-strict'
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.firestore.document("Users/{user_id}/Notifications/{notification_id}").onWrite(event => {
const user_id = event.params.user_id;
const notification_id = event.params.notification_id;
console.console.log("User ID: " + user_id + " | Notification ID: " + notification_id);
});
Error in Logs of Firebase Functions
TypeError: Cannot read property 'user_id' of undefined at
exports.sendNotification.functions.firestore.document.onWrite.event
(/user_code/index.js:10:33) at Object.<anonymous>
(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112: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:82:36) at
/var/tmp/worker/worker.js:700:26 at process._tickDomainCallback
(internal/process/next_tick.js:135:7)
Database Rules
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true; } } }
It looks like you're using version 1.0 of the firebase-functions module in your Cloud Functions code. The API has changed in 1.0. Please consult the migration guide to understand what changed in 1.0.
There is no longer a params
property on the first argument passed to the the callback for an onWrite trigger. It was split into two arguments , a Change, and an EventContext object. The EventContext argument has a params property you should use now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.