【发布时间】:2018-07-20 15:04:30
【问题描述】:
当我以编程方式将内容添加到 firestore 时,我的函数不会触发,它只会在我从控制台手动添加数据时执行。
这是我的功能:
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));
});
【问题讨论】:
-
{app]是文档还是集合? -
@RodrigoMata 一个文档
-
你能展示你用来以编程方式添加“东西”的代码吗?以编程方式添加数据后,它会显示在控制台中吗?
标签: javascript firebase google-cloud-firestore google-cloud-functions