0

I have a collection 'Cart' in firebase cloud fire store, in that collection I have 10 documents.

{1,2,3,4,5,6,7,8,9,10} these are the documents name or id.

I have a list view where I am getting the ids of the document and from that list I am selecting and trying to delete those.

I am trying to delete multiple documents from that collection.

I am trying to delete documents(6,2,7,4,5).

in firebase docs there is only how to delete single and multiple documents from fire store

so how can to implement this in flutter??

please help

Cobolt
  • 935
  • 2
  • 11
  • 24
  • https://stackoverflow.com/questions/48175235/how-to-delete-multiple-documents-from-cloud-firestore#:~:text=To%20delete%20multiple%20documents%2C%20you,()%20method%20for%20this%20purpose. – stacktrace2234 Aug 20 '21 at 08:27

1 Answers1

0

Obviously Firebase Firestore has no way to delete multiple documents, you can use for loop to achieve that. You can make a list of the ids which you want to delete in Firestore lets say

List _deletedIds = [6,2,7,4,5];
    for (var i = 0 ; i <= _deletedIds.length - 1 ; i++){
      FirebaseFirestore.instance.collection('Cart').doc(_deletedIds[i]).delete();
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Moataz Fouuad
  • 63
  • 1
  • 5