Batches
Helpers for batch requests to the Google Cloud Firestore API.
class google.cloud.firestore_v1.batch.WriteBatch(client)
Bases: object
Accumulate write operations to be sent in a batch.
This has the same set of methods for write operations that
DocumentReference
does,
e.g. create()
.
Parameters
client (
Client
) – The client that created this batch.
commit()
Commit the changes accumulated in this batch.
Returns
The write results corresponding to the changes committed, returned in the same order as the changes were applied to this batch. A write result contains an
update_time
field.Return type
List[
google.cloud.proto.firestore.v1.write_pb2.WriteResult
, …]
create(reference, document_data)
Add a “change” to this batch to create a document.
If the document given by reference
already exists, then this
batch will fail when commit()
-ed.
Parameters
reference (
DocumentReference
) – A document reference to be created in this batch.document_data (dict) – Property names and values to use for creating a document.
delete(reference, option=None)
Add a “change” to delete a document.
See
google.cloud.firestore_v1.document.DocumentReference.delete()
for more information on how option
determines how the change is
applied.
Parameters
reference (
DocumentReference
) – A document reference that will be deleted in this batch.option (Optional[
WriteOption
]) – A write option to make assertions / preconditions on the server state of the document before applying changes.
set(reference, document_data, merge=False)
Add a “change” to replace a document.
See
google.cloud.firestore_v1.document.DocumentReference.set()
for
more information on how option
determines how the change is
applied.
Parameters
reference (
DocumentReference
) – A document reference that will have values set in this batch.document_data (dict) – Property names and values to use for replacing a document.
merge (Optional[bool] or **Optional[List]) – If True, apply merging instead of overwriting the state of the document.
update(reference, field_updates, option=None)
Add a “change” to update a document.
See
google.cloud.firestore_v1.document.DocumentReference.update()
for more information on field_updates
and option
.
Parameters
reference (
DocumentReference
) – A document reference that will be updated in this batch.field_updates (dict) – Field names or paths to update and values to update with.
option (Optional[
WriteOption
]) – A write option to make assertions / preconditions on the server state of the document before applying changes.