-1

this is my function for deleting a document in my "files" collection

Future<void> deleteProgram(String id, String program) async {
    try {
      print(id + "----" + program);
      await firestoreInstance.collection("files").doc(program).delete();
      // await firestoreInstance.collection("programs").doc(id).delete();
      print("done");
    } catch (e) {
      print(e);
    }  
  }

program is the id of the document, when i use this nothing gets deleted, even if i hardcode the ID.

this is what my collection looks like: enter image description here

as you can see, each document in the files collection also has a subcollection called files

what am i doing wrong here?

venum
  • 83
  • 9

1 Answers1

2

The only way to delete a collection is to delete each individual document from it. There is no atomic operation to delete a collection.

In your screenshot the opleiding4 is shown in italic, meaning that this document doesn't really exist, and the Firebase console merely shows that name to be able to show its files subcollection.

Once you delete all files from the /files/opeleiding4/files subcollection both that collection and its parent document will disappear from the Firebase console too.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807