I have been trying to solve this problem for several days… Any help is greatly appreciated.
I am trying to build a Firebase Cloud Function that is triggered from a Pub/sub topic (‘ETACheck’). The triggering part is working fine. When the cloud function is invoked, it scans the Firebase database looking for all records where ’ECT’ key equals to ‘’. Here is how the data is organized:
Here is the code snippet:
exports.CheckETAResponse = functions.pubsub.topic('ETACheck').onPublish((message, context) => {
console.log('The function was triggered at ', context.timestamp);
console.log('The unique ID for the event is', context.eventId);
var db = admin.database();
var ref = db.ref('{company}/Requisitions/{store}');
return ref.orderByChild('ECT').equalTo('').on('value')
.then((snapshot) => {
if (snapshot !== null) {
const data = snapshot.val();
console.log('Data',data);
}
else {
console.log('Snapshot is null');
}
return null;
})
.catch((error) => console.log('Error',error))
});
And the error from Firebase (data = null):
I changed the query to “.on(‘child_added’), and I got the following error: