updateDocument<ID extends Object?> method

  1. @override
Future<void> updateDocument<ID extends Object?>(
  1. String collectionPath,
  2. ID documentId,
  3. Map<String, Object?> data
)
override

Updates data on the document. Data will be merged with any existing document data.

If no document exists yet, the update will fail.

Implementation

@override
Future<void> updateDocument<ID extends Object?>(
    String collectionPath, ID documentId, Map<String, Object?> data) async {
  final storage = await getStorage(collectionPath);
  final existing =
      storage.read(documentId.toString()) as Map<String, Object?>?;

  if (existing == null) {
    throw 'GetStorageDelegate.update: there is no doc to update (id=$documentId)';
  } else {
    return storage.write(
        documentId.toString(), <String, Object?>{...existing, ...data});
  }
}