'Flutter Firebase delete a document of a subcollection using the document ID

Apparently, I was able to retrieve a subcollection data from firebase by using the code below

FirebaseFirestore.instance.collectionGroup('announcementlist').where('id', isEqualTo: '${docID}');

However, I am now trying to delete a subcollection by using this collectionGroup method and it is not working. I want all admin user to be able to delete the subcollections.

So what I found online is something similar to this line of code.

// define document location (Collection Name > Document Name > Collection Name >)
var docRef = Firebase.firestore().collection("Rooms").doc("bsYNIwEkjP237Ela6fUp").collection("Messages");

// delete the document
docRef.doc("lKjNIwEkjP537Ela6fhJ").delete();

which I got from codegrepper but as far as I know, the doc("bsYNIwEkjP237Ela6fUp") part requires the id of the user which is not the method I want because all admin users should be able to delete the data and it uses collection instead of collectiongroup

Is there any solution for this ? Please help.



Solution 1:[1]

FirebaseFirestore.instance.collection("Rooms").doc(snapshot.requireData.docs[i].id).collection("Messages").doc(snapshot.requireData.docs[i].id).delete();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zeel Patel