Sorry for the cluttered notation of document and subcollection.
I did a lot of research there, but ... ・ Delete using Cloud Fuctions -Write a method to fetch the comment document separately and delete it Only articles.
CloudFuctions seems to be deprecated because it is too slow.
So, as a result of careful consideration while looking at the Tutorial,
func delete(collection: CollectionReference, batchSize: Int = 100, completion: @escaping (Error?) -> ()) {
collection.limit(to: batchSize).getDocuments { (docset, error) in
guard let docset = docset else {
completion(error)
return
}
guard docset.count > 0 else {
completion(nil)
return
}
let batch = collection.firestore.batch()
docset.documents.forEach {batch.deleteDocument($0.reference)}
batch.commit { (batchError) in
if let batchError = batchError {
completion(batchError)
}
else {
self.delete(collection: collection, batchSize: batchSize, completion: completion)
}
}
}
}
This function worked fine. Please apply the completion part according to what you want to make.
It's for my own memo, and I hope it helps because anyone can do it.
Recommended Posts