【发布时间】:2019-07-25 05:51:30
【问题描述】:
我正在建立某种社交网络。为了保存读取操作,对于每篇文章,我都会将作者的详细信息(图像和名称)存储在其中。 我正在尝试创建一个云功能,当用户编辑他们的个人资料详细信息时,该功能将更改用户撰写的所有帖子并相应地更新它们(使用新名称/图像)。
我面临的问题(不是什么大问题,只是想提高效率),我如何编辑该用户的所有帖子? 我是否必须先查询该用户的所有帖子,然后遍历结果以更改它们? 或者有什么方法可以让我编辑所有符合特定条件的文档?
这是我现在的函数,我放在了我希望存在的假设函数中。
exports.updateUser = functions.firestore.document('communities_data/{community}/profiles/{profileID}').onUpdate((change, context) => {
// Retrieve the current and previous value
const data = change.after.data();
const previousData = change.before.data();
// We'll only update if the name has changed.
// This is crucial to prevent infinite loops.
if (data !== undefined && previousData !== undefined) {
if (data.name !== previousData.name || data.image !== previousData.image) {
//I am looking for something like this
return db.doc('communities_data/' + context.params.community + '/questions').where('author_ID', '==', context.params.profileID).set
} else {
return null;
}
} else {
return null;
}
});
【问题讨论】:
标签: typescript firebase google-cloud-firestore google-cloud-functions