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('🔥 Batch deleting ${collectionPathOverride ?? _collectionPath()} document with '
'id: $id, '
'writeBatch: $writeBatch..');
final nullSafeWriteBatch = writeBatch ?? this.writeBatch;
final documentReference = findDocRef(id: id, collectionPathOverride: collectionPathOverride);
_log.value(documentReference.id, '🔥 Document ID');
_log.info('🔥 Deleting data with writeBatch.delete..');
nullSafeWriteBatch.delete(documentReference);
_log.success('🔥 Adding delete to batch done! Returning WriteBatchWithReference..');
return FeedbackResponse.successNone(
result: WriteBatchWithReference(
writeBatch: nullSafeWriteBatch,
documentReference: documentReference,
),
);
} catch (error, stackTrace) {
_log.error(
'🔥 Unable to batch delete ${collectionPathOverride ?? _collectionPath()} document with id: $id',
error: error,
stackTrace: stackTrace,
);
return _responseConfig.deleteFailedResponse(isPlural: writeBatch != null);
}
}