batchDeleteDoc method
Batch deletes data based on given id
.
Passing in a writeBatch
will use that batch to add to it. If no batch is provided this
method will create and return one.
Implementation
Future<FeedbackResponse<WriteBatchWithReference?>> batchDeleteDoc({
required String id,
WriteBatch? writeBatch,
String? collectionPathOverride,
}) async {
assert(
_isCollectionGroup == (collectionPathOverride != null),
'Firestore does not support finding a document by id when communicating with a collection group, '
'therefore, you must specify the collectionPathOverride containing all parent collection and document ids '
'in order to make this method work.',
);
try {
_log.info(
message: 'Deleting document with batch..',
sensitiveData: _shouldNotSensitiveInfo
? null
: SensitiveData(
path: collectionPathOverride ?? _collectionPath(),
id: id,
isBatch: writeBatch != null,
),
);
final nullSafeWriteBatch = writeBatch ?? this.writeBatch;
final documentReference =
findDocRef(id: id, collectionPathOverride: collectionPathOverride);
_log.info(
message: 'Deleting data with writeBatch.delete..',
sensitiveData: null,
);
nullSafeWriteBatch.delete(documentReference);
_log.success(
message:
'Adding delete to batch done! Returning WriteBatchWithReference..',
sensitiveData: null,
);
return FeedbackResponse.successNone(
result: WriteBatchWithReference(
writeBatch: nullSafeWriteBatch,
documentReference: documentReference,
),
);
} catch (error, stackTrace) {
_log.error(
message: 'Unable to delete document with batch',
sensitiveData: _shouldNotSensitiveError
? null
: SensitiveData(
path: collectionPathOverride ?? _collectionPath(),
id: id,
),
error: error,
stackTrace: stackTrace,
);
return _responseConfig.deleteFailedResponse(isPlural: writeBatch != null);
}
}