Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.handler = functions.firestore.document('/Polls/{pollId}/followers/{followerId}').onCreate((data, context) => {
- const followerId = data.data().follower_id;
- const userId = admin.firestore().doc(`Polls/${context.params.pollId}`/{user_id:doc.data().user_id});
- //iterate through all collections under "Polls"
- const parentRef = admin.database().ref("Polls");
- return parentRef.once('value').then(snapshot => {
- const updates = {};
- snapshot.forEach(function(child) {
- //if the collection has user_ID field == the user id of the the wildcard pollId, add the follwerId the
- if (child.pollid.userId == userId){
- //write that user ID to the "followers" subcollection of that node
- }
- });
- return parentRef.update(updates);
- });
- });
Add Comment
Please, Sign In to add comment