0

enter image description hereso I want to push notifications from device to device and I'm using firebase cloud functions for that and of course node.js as I was searching I found out that there is a new method to retrieve id from firebase firestore but no one explained it in a good way anyway here is the node.js index.js that I'm getting this following error :

TypeError: Cannot read property 'pharmacien_id' of undefined
at exports.sendCommandes.functions.firestore.document.onWrite.event (/user_code/index.js:8:35)
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:710:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

and here is the index.js:

'use-strict'

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


exports.sendCommandes=functions.firestore.document("Pharmaciens/{pharmacien_id}
   /Commandes/{commande_id}").onWrite(event =>{
  const pharmacien_id=event.params.pharmacien_id;
  const commande_id=event.params.commande_id;
  console.log("pharmacien_id: "+pharmacien_id+" |commande_id: "+commande_id);
});
yoyo guen
  • 37
  • 6

1 Answers1

1

Solution:
change event with (change,context) and event.params.uid with context.params.uid

yoyo guen
  • 37
  • 6