many<T> method

Future<void> many<T>(
  1. List<T> objects, {
  2. String? subcollection,
})

Deletes multiple documents from Firestore using a list of objects.

Implementation

Future<void> many<T>(List<T> objects, { String? subcollection }) {
  if (objects.isEmpty) return Future.value();
  if (objects.length > 500) {
    throw ArgumentError('Batch delete limit exceeded. Maximum 500 objects allowed.');
  }

  List<Future<void>> futures = [];
  for (dynamic object in objects) {
    if (object.id == null) {
      continue; //skip
    }
    DocumentReference ref = FS.instance.collection(object.runtimeType.toString()).doc(object.id);
    if (subcollection != null) {
      ref = FS.instance.collection(object.runtimeType.toString()).doc(subcollection).collection(subcollection).doc(object.id);
    }
    futures.add(ref.delete());
  }
  return Future.wait(futures);
}