【发布时间】:2019-12-17 07:53:00
【问题描述】:
所以我有这样的可调用云函数:
const db = admin.firestore()
exports.changeEventDataInUserSubcollection = functions.https.onCall(async (data, context) => {
const updatedKey = data.updatedKey
const updatedValue = data.updatedValue
const creatorID = data.creatorID
const eventID = data.eventID
try {
return db.doc(`users/${creatorID}/createdEvents/${eventID}`).update({updatedKey: updatedValue})
} catch (error) {
console.log(error)
return Promise.resolve(null)
}
})
正如您在.update({updatedKey: updatedValue}) 中看到的,我想从客户端设置键和值。所以我可以动态更新文档。我希望 updatedKey 和 updatedValue 来自客户端
但我上面的代码似乎不起作用,因为我有这个警告:
updatedKey 已声明但从未使用过。那么如何在更新 Firestore 文档时动态更改键和值呢?我可以这样做吗?
【问题讨论】:
标签: javascript firebase google-cloud-firestore google-cloud-functions