Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
This repository was archived by the owner on May 19, 2025. It is now read-only.

step 17. Handling denormalized data #40

@uniqby

Description

@uniqby

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}`);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions