简体   繁体   English

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

[英]how to delete all documents on firestore using javascript

i try this code for my project but on doc.reference.delete() is not working我为我的项目尝试此代码,但在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);
    });

how to solve this?如何解决这个问题?

Try this, db have to be a const !试试这个, db 必须是 const ! I think there is the problem我认为有问题

const db = new Firestore({
  projectId: "projectId",
  keyFilename: "./key.json"
 });
db.collection("collectionName")
  .get()
  .then(res => {
    res.forEach(element => {
      element.ref.delete();
    });
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM