【发布时间】:2018-09-02 05:36:38
【问题描述】:
我观看此视频以使用事务更新实时数据库中的数据:https://www.youtube.com/watch?v=TPKA88_FmkA,但似乎在 firestore 云功能上无法使用事务?
所以我有这样的 Firestore 数据,我想在子集合中添加新参与者时更新 rankPoint。
这是我用来触发函数的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin')
admin.initializeApp()
exports.increasePointWhenAddingNewAttendee = functions.firestore
.document('Events/{eventId}/Attendee/{userId}')
.onCreate((snap, context) => {
const eventID = context.params.eventId
const eventRef = snap.ref.firestore.collection('Events').doc(eventID)
// increase rankPoint
return eventRef.transaction(rankPoint => {
return rankPoint + 1
})
});
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions