title: Firestore Error: too much contention on these documents, please try again
body: <p>I am using Google Cloud Firestore to save some documents using a Python script. In Cloud Firestore, my data is divided up into collections and documents. Documents point to subcollections that contain other documents (collection group).
  I execute multiple write operations as a single batch (<a href="https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes" rel="nofollow noreferrer">link</a> to documentation), but sometimes I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/local/lib/python3.7/dist-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
      return callable_(*args, **kwargs)
    File "/usr/local/lib/python3.7/dist-packages/grpc/_channel.py", line 690, in __call__
      return _end_unary_response_blocking(state, call, False, None)
    File "/usr/local/lib/python3.7/dist-packages/grpc/_channel.py", line 592, in _end_unary_response_blocking
      raise _Rendezvous(state, None, None, deadline)
  grpc._channel._Rendezvous: &lt;_Rendezvous of RPC that terminated with:
      status = StatusCode.ABORTED
      details = "Too much contention on these documents. Please try again."
      debug_error_string = "{"created":"@1587693610.322629065","description":"Error received from peer ipv4:173.194.76.95:443","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Too much contention on these documents. Please try again.","grpc_status":10}"
  </code></pre>
  
  <p>The function I use to save my collection group documents is the following:</p>
  
  <pre><code>from google.cloud import firestore  #1.6.0
  import time
  
  def save(docs):
      """saving in Firestore using collection_group"""
  
      #chunk of 500 (batch commit does not support more than 500 savings at a time)
      docs_chunk=[docs[i:i+499] for i in range(0, len(docs), 500)]
      db = firestore.Client()
      for c in docs_chunk:
          batch = db.batch()
          for doc in c:
              c = db.collection('COLLECTION_NAME').document('DOCUMENT_NAME').collection('SUB_COLLECTION_NAME').document('SUB_DOCUMENT_NAME')
              batch.set(c, doc)
          batch.commit()
          time.sleep(5)
  </code></pre>
  
  <p>What does this error mean? Sometimes, if I re-run the script, the error does not occur any more.</p>