Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step 17. Handling denormalized data #40

Open
uniqby opened this issue Apr 29, 2020 · 1 comment
Open

step 17. Handling denormalized data #40

uniqby opened this issue Apr 29, 2020 · 1 comment

Comments

@uniqby
Copy link

uniqby commented Apr 29, 2020

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}`);
}
@ToddKerpelman
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants