Deleting all documents in Firestore collection

后端 未结 7 867
我在风中等你
我在风中等你 2020-11-30 06:51

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.

7条回答
  •  一整个雨季
    2020-11-30 06:54

    Tested in VueJS

    import db from '@/firebase/init' 
    
    let ref = db.collection('YOUR_COLLECTION_NAME')
    
    db.collection(path).onSnapshot(snapshot => {
        snapshot.docs.forEach(doc => {
            ref.doc(doc.id).delete()
            .catch(error => {
                console.log(error)
            })
        })
    })
    
    

提交回复
热议问题