update method
Adds an update of the fields in data of the existing document
documentRef. Fields that are not in data keep their values.
The keys of data are field paths, a String or a FieldPath: in a
String a dot reaches into a nested map, so
'address.city' changes only city inside address. The values can
be FieldValue sentinels, for example FieldValue.delete to remove a
field. A converter of documentRef is not used: data is always a
map.
batch.update(firestore.doc('cities/SF'), <String, Object?>{
'address.city': 'San Francisco',
'updatedAt': FieldValue.serverTimestamp(),
});
The document must exist when the batch is committed. If it does not, commit fails with FirestoreErrorCode.notFound and none of the writes of the batch is applied.
Throws an ArgumentError if data holds an invalid field path or
value, or if documentRef belongs to another FirebaseFirestore instance.
Throws a StateError if the batch was already committed.
Returns this batch, so that calls can be chained.
Implementation
WriteBatch update(
DocumentReference<Object?> documentRef,
Map<Object, Object?> data,
) {
final UserDataParsedUpdateData parsedData = _firestore.dataConverter
.parseUpdateMap(
data,
methodName: 'WriteBatch.update',
targetDoc: documentRef.key,
);
_firestore.validateReference(documentRef);
_verifyNotCommitted();
_mutations.add(
parsedData.toMutation(documentRef.key, Precondition(exists: true)),
);
return this;
}