WriteBatch

class WriteBatch : NSObject

A write batch is used to perform multiple writes as a single atomic unit.

A WriteBatch object can be acquired by calling [FIRFirestore batch]. It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) until [FIRWriteBatch commit] is called.

Unlike transactions, write batches are persisted offline and therefore are preferable when you don’t need to condition your writes on read data.

  • Writes to the document referred to by document. If the document doesn’t yet exist, this method creates it and then sets the data. If the document exists, this method overwrites the document data with the new values.

    Declaration

    Swift

    func setData(_ data: [String : Any], forDocument document: FIRDocumentReference) -> WriteBatch

    Parameters

    data

    An NSDictionary that contains the fields and data to write to the document.

    document

    A reference to the document whose data should be overwritten.

    Return Value

    This FIRWriteBatch instance. Used for chaining method calls.

  • Writes to the document referred to by document. If the document doesn’t yet exist, this method creates it and then sets the data. If you pass merge:YES, the provided data will be merged into any existing document.

    Declaration

    Swift

    func setData(_ data: [String : Any], forDocument document: FIRDocumentReference, merge: Bool) -> WriteBatch

    Parameters

    data

    An NSDictionary that contains the fields and data to write to the document.

    document

    A reference to the docume