Incrementing a Firestore document field while using shards (async)

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

Incrementing a Firestore document field while using shards (async).

Explore further

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

Code sample

Python

async def increment_counter(self, doc_ref):
    """Increment a randomly picked shard."""
    doc_id = random.randint(0, self._num_shards - 1)

    shard_ref = doc_ref.collection("shards").document(str(doc_id))
    return await shard_ref.update({"count": firestore.Increment(1)})

What's next

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