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.
You have to get all the documents then use batch to delete them in bulk P.S. i prefer try...catch syntax
let deleteInBatch = async (query, size = 100) => {
try{
let batch = firestore().batch();
//get documents
let values = await query.get();
if(values.size>0){
values.foreach(value=> {
batch.delete(value.ref);
})
//Delete the documents in bulk
batch.commit();
if(values.size>0){
//Recusively call the function again to finish
//deleting the rest of documents
deleteInBatch(query,size);
}
}else{
//exist function
return;
}
}catch(err){
throw err;
}
}