如何使用javascript删除Firestore上的所有文档

问题描述 投票:0回答:1

我尝试为我的项目使用此代码,但在doc.reference.delete()上不起作用

 btnSubmit.addEventListener('click', e => {
    db.collection("ruangIGD")
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            // doc.data() is never undefined for query doc snapshots

            doc.reference.delete()
        });
    })
    .catch(function(error) {
        console.log("Error getting documents: ", error);
    });

如何解决这个问题?

javascript firebase google-cloud-firestore
1个回答
0
投票

尝试一下,db必须是一个const!我认为有问题

const db = new Firestore({
  projectId: "projectId",
  keyFilename: "./key.json"
 });
db.collection("collectionName")
  .get()
  .then(res => {
    res.forEach(element => {
      element.ref.delete();
    });
 });
© www.soinside.com 2019 - 2024. All rights reserved.