Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

511
Views
Firebase Firestore deleteDoc() not working

I am working on my first Web App using firebase and I have hit a problem I can't find the solution to. I am trying to delete a document by Id, The function works fine however the document is not deleted. I have set the Firestore rules to allow delete as well. However it's still not working. I'll leave the relevant code and rules here:

Code

function del(x){
      console.log("Delete File : "+filesListID[x-1]);
      console.log("File : "+fileList[x-1].fileno + " " +decrypt(fileList[x-1].fileno));
      deleteDoc(doc(firestore,"property",filesListID[x])).then( function(){
          var table = document.getElementById("userlist");
          table.innerHTML = "";
          userList();
          alert("File Deleted Successfully");
      }).catch((error) => {
        console.log("Error Deleting Property List: "+error);
      });
      
}

Rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write, delete: if request.auth != null;
    }
  }
}

I can't figure out what's going wrong here, any suggestions will be helpful, Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe you want to delete filesListID [x-1] but inside deleteDoc() you have mentioned filesListID [x]. And at the top of that, before deleting, you could also check if filesListID [x-1] exists or not.

function del(x) {
  console.log("Delete File : " + filesListID[x - 1]);
  console.log("File : " + fileList[x - 1].fileno + " " + decrypt(fileList[x - 1].fileno));
  deleteDoc(doc(firestore, "property", filesListID[x - 1])).then(function() {
    var table = document.getElementById("userlist");
    table.innerHTML = "";
    userList();
    alert("File Deleted Successfully");
  }).catch((error) => {
    console.log("Error Deleting Property List: " + error);
  });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!