I\'m looking for a way to clear an entire collection. I saw that there is a batch update option, but that would require me to know all of the document IDs in the collection.
The following javascript function will delete any collection:
deleteCollection(path) {
firebase.firestore().collection(path).listDocuments().then(val => {
val.map((val) => {
val.delete()
})
})
}
This works by iterating through every document and deleting each.
Alternatively, you can make use of Firestore's batch commands and delete all at once using the following function:
deleteCollection(path) {
// Get a new write batch
var batch = firebase.firestore().batch()
firebase.firestore().collection(path).listDocuments().then(val => {
val.map((val) => {
batch.delete(val)
})
batch.commit()
})
}