Updating a Firestore document in a transaction (async)

Stay organized with collections Save and categorize content based on your preferences.

Updating a Firestore document in a transaction (async).

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


transaction = db.transaction()
city_ref = db.collection("cities").document("SF")

async def update_in_transaction(transaction, city_ref):
    snapshot = await city_ref.get(transaction=transaction)
    transaction.update(city_ref, {"population": snapshot.get("population") + 1})

await update_in_transaction(transaction, city_ref)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.