コレクション全体を消去する方法を探しています。バッチ更新オプションがあることがわかりましたが、コレクションのすべてのドキュメントIDを知っている必要があります。Firestoreコレクションのすべての文書を削除する
私はコレクション内のすべてのドキュメントを単に削除する方法を探しています。
ありがとうございます!
編集:以下の答えは、私は次のように使用し、正しいです:
func delete(collection: CollectionReference, batchSize: Int = 100) {
// Limit query to avoid out-of-memory errors on large collections.
// When deleting a collection guaranteed to fit in memory, batching can be avoided entirely.
collection.limit(to: batchSize).getDocuments { (docset, error) in
// An error occurred.
let docset = docset
let batch = collection.firestore.batch()
docset?.documents.forEach { batch.deleteDocument($0.reference) }
batch.commit {_ in
self.delete(collection: collection, batchSize: batchSize)
}
}
}