manyWithIDs method

  1. @override
Future<void> manyWithIDs(
  1. Type type,
  2. List<String> documentIDs, {
  3. String? subcollection,
})
override

Deletes multiple documents from Firestore by their type and a list of document IDs.

Implementation

@override
Future<void> manyWithIDs(Type type, List<String> documentIDs, { String? subcollection }) async {
  if (documentIDs.isEmpty) return;
  if (documentIDs.length > 500) {
    throw ArgumentError('Batch limit exceeded. Maximum 500 document IDs allowed.');
  }

  List<Future> futures = [];

  for (String id in documentIDs) {
    DocumentRef ref = LS.instance.collection(type.toString()).doc(id);
    if (subcollection != null) {
      ref = LS.instance.collection(type.toString()).doc(subcollection).collection(subcollection).doc(id);
    }
    futures.add(ref.delete());
  }
  await Future.wait(futures);
}