I have this node js function that attempts to update Algolia index once a add/update/delete is done to node Listings
exports.indexlisting_algolia =
functions.database.ref('/Listings/{listingId}').onWrite((snapshot, context) => {
const index = algolia.initIndex('Listings');
// var firebaseObject = snapshot.data;
var firebaseObject = snapshot.data.val();
console.log("test ",firebaseObject)
firebaseObject.objectID = context.params.listingId;
return index.saveObject(firebaseObject).then(
() =>
snapshot.data.adminRef.parent.child('last_index_timestamp').set(
Date.parse(event.timestamp)));
});
this is my error thraceback
TypeError: Cannot read property 'val' of undefined at exports.indexlisting_algolia.functions.database.ref.onWrite (/user_code/index.js:807:40) at Object. (/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:733:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
line 807 is this function
var firebaseObject = snapshot.data.val();
what am I doing wrongly and how can I fix this?