firestore-codelab-extended-swift icon indicating copy to clipboard operation
firestore-codelab-extended-swift copied to clipboard

step 17. Handling denormalized data

Open uniqby opened this issue 5 years ago • 1 comments

Option 2: Change data server-side with Cloud Functions

batch.update() func returns WriteBatch instance itself, not Promise. So await is not needed.

// update changes to restaurant
async function updateRestaurant(db: Firestore, restaurantID: string, name: string) {
    const updateRef = db.collection('reviews');
    // query a list of reviews of the restaurant
    const queryRef = updateRef.where('restaurantID', '==', restaurantID);
    const batch = db.batch();
    const reviewsSnapshot = await queryRef.get();
    for (const doc of reviewsSnapshot.docs) {
         await batch.update(doc.ref, {restaurantName: name}); <---  HERE!
    };
    await batch.commit();
    console.log(`name of restaurant updated to ${name}`);
}

uniqby avatar Apr 29 '20 15:04 uniqby

Good catch! At some point, I promise we'll revise this codelab, and I'll make sure to incorporate your feedback.

ToddKerpelman avatar May 01 '20 18:05 ToddKerpelman