Lets say I have two top level collection with users and stories. Now everytime a document from user gets update (only the values username
or photoUrl
), I want to update these properties on a document from the story collection.
One users doc could look like this (shortened):
{
username: 'blubber',
photoUrl: 'my/photo/path',
uid: 'usersUniqueId'
}
The story doc could look like this (shortened):
{
username: 'blubber',
photoUrl: 'my/photo/path',
uid: 'usersUniqueId',
sid: 'storiesUniqueId,
content: '...'
}
Now on the cloud functions part. I dont now how to query all documents from the stories collection that contains the users id. The code from now looks like this:
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;
}
});
Can anyone help me out on this?