users<Collection> -> userId<Document> -> transactions<Collection> -> List(doc - to be deleted)
let's assume this as the collection we will talk about
To delete all documents in a collection along with the collection itself,
you need to first delete the List(doc - to be deleted)
in a batch
// batch to delete all transactions associated with a user doc
final WriteBatch batch = FirebaseFirestore.instance.batch();
// Delete the doc in [FirestoreStrings.transactionCollection] collection
await _exchangesCollection
.doc(docId)
.collection("transaction")
.get()
.then((snap) async {
for (var doc in snap.docs) {
batch.delete(doc.reference);
}
// execute the batch
await batch.commit();
and then delete the doc userId<Document>
which holds the transactions<Collection>
By this way you might have to get rid of the entire userId<Document>
itself , but its the only way around to get rid of it completely.
else you can skip the second step of deleting the doc to get rid of the collection, which is totally fine as the collection ref in a doc serves just as the field of the doc.