[英]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.我正在使用 firebase 开发我的第一个 Web 应用程序,我遇到了一个我找不到解决方案的问题。 I am trying to delete a document by Id, The function works fine however the document is not deleted.
我正在尝试通过 Id 删除文档,function 工作正常但是文档没有被删除。 I have set the Firestore rules to allow delete as well.
我已将 Firestore 规则设置为也允许删除。 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!我不知道这里出了什么问题,任何建议都会有所帮助,谢谢!
I believe you want to delete filesListID [x-1]
but inside deleteDoc()
you have mentioned filesListID [x]
.我相信您想删除
filesListID [x-1]
但在deleteDoc()
中您提到filesListID [x]
。 And at the top of that, before deleting, you could also check if filesListID [x-1]
exists or not.最重要的是,在删除之前,您还可以检查
filesListID [x-1]
是否存在。
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);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.