【发布时间】:2019-04-16 03:07:49
【问题描述】:
假设我有两个包含用户和故事的顶级集合。现在,每次来自用户的文档得到更新(仅值 username 或 photoUrl),我想更新故事集合中文档的这些属性。
一个用户文档可能如下所示(缩短):
{
username: 'blubber',
photoUrl: 'my/photo/path',
uid: 'usersUniqueId'
}
故事文档可能如下所示(缩短):
{
username: 'blubber',
photoUrl: 'my/photo/path',
uid: 'usersUniqueId',
sid: 'storiesUniqueId,
content: '...'
}
现在是云功能部分。我现在不知道如何从包含用户 ID 的故事集合中查询所有文档。现在的代码如下所示:
export const onUpdateUser = functions.firestore.document('/users/{userId}')
.onUpdate((change, context) => {
const before = change.before.data();
const after = change.after.data();
if(before.username !== after.username || before.photoURL !== after.photoURL) {
return admin.firestore().collection('/stories/')
.where(before.uid, '==', ***fetch the comparison***)
// do something
} else {
return null;
}
});
谁能帮我解决这个问题?
【问题讨论】:
标签: typescript firebase google-cloud-firestore google-cloud-functions