I'm having trouble getting my function to trigger when I programmatically add data to Firestore. It only seems to work when I manually add data through the console.
Below is the code for my function:
exports.updateFirestoreStatistics = functions.firestore.document('applications/2018/all/{app}').onWrite(change => {
let ref = db.collection('statistics').doc('2018');
let t = db.runTransaction(transaction => {
return transaction.get(ref).then(doc => {
let updatedAppCount = doc.data().applications + 1
return transaction.update(ref, {applications: updatedAppCount});
})
}).then(() => console.log('Stat updated! ')).catch(err => console.log('An error occured ', err));
});