update method

Future<WriteResult> update(
  1. Map<Object?, Object?> data, [
  2. Precondition? precondition
])

Updates fields in the document referred to by this DocumentReference. If the document doesn't yet exist, the update fails and the returned Promise will be rejected.

The update() method accepts either an object with field paths encoded as keys and field values encoded as values, or a variable number of arguments that alternate between field paths and field values.

A Precondition restricting this update can be specified as the last argument.

Implementation

Future<WriteResult> update(
  Map<Object?, Object?> data, [
  Precondition? precondition,
]) async {
  final writeBatch = WriteBatch._(this.firestore)
    ..update(
      this,
      {
        for (final entry in data.entries)
          FieldPath.from(entry.key): entry.value,
      },
      precondition: precondition,
    );

  final results = await writeBatch.commit();
  return results.single;
}