code: def reference_value_to_document(reference_value, client):
      
      # The first 5 parts are
      # projects, {project}, databases, {database}, documents
      parts = reference_value.split(DOCUMENT_PATH_DELIMITER, 5)
      if len(parts) != 6:
          msg = BAD_REFERENCE_ERROR.format(reference_value)
          raise ValueError(msg)
  
      # The sixth part is `a/b/c/d` (i.e. the document path)
      document = client.document(parts[-1])
      if document._document_path != reference_value:
          msg = WRONG_APP_REFERENCE.format(reference_value, client._database_string)
          raise ValueError(msg)
  
      return document
docs: Convert a reference value string to a document.
  
      Args:
          reference_value (str): A document reference value.
          client (~.firestore_v1beta1.client.Client): A client that has
              a document factory.
  
      Returns:
          ~.firestore_v1beta1.document.DocumentReference: The document
          corresponding to ``reference_value``.
  
      Raises:
          ValueError: If the ``reference_value`` is not of the expected
              format: ``projects/{project}/databases/{database}/documents/...``.
          ValueError: If the ``reference_value`` does not come from the same
              project / database combination as the ``client``.