Class BaseWriteBatch (2.2.0)

BaseWriteBatch(client)

Accumulate write operations to be sent in a batch.

This has the same set of methods for write operations that xref_DocumentReference does, e.g. xref_create.

Parameter

NameDescription
client Client

The client that created this batch.

Methods

create

create(
    reference: google.cloud.firestore_v1.document.DocumentReference, document_data: dict
)

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
NameDescription
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

delete(
    reference: google.cloud.firestore_v1.document.DocumentReference,
    option: Optional[google.cloud.firestore_v1._helpers.WriteOption] = None,
)

Add a "change" to delete a document.

See xref_delete for more information on how option determines how the change is applied.

Parameters
NameDescription
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

set(
    reference: google.cloud.firestore_v1.document.DocumentReference,
    document_data: dict,
    merge: Union[bool, list] = False,
)

Add a "change" to replace a document.

See xref_set for more information on how option determines how the change is applied.

Parameters
NameDescription
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

update(
    reference: google.cloud.firestore_v1.document.DocumentReference,
    field_updates: dict,
    option: Optional[google.cloud.firestore_v1._helpers.WriteOption] = None,
)

Add a "change" to update a document.

See xref_update for more information on field_updates and option.

Parameters
NameDescription
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.