reactjs - 使用firebase firestore删除文档功能的问题(代码运行,文档仍然存在于firestore中)-React / Typescript / Redux
问题描述
根据标题,我不确定我是否做错了什么,但我无法使用我的代码删除文档;尽管代码似乎运行没有打嗝。我可以确认文档 ID 存在于 firestore 中,其中也没有子集合(据我所知,删除与子集合很奇怪)。
代码在这里
删除功能
export const deletePost = (
docId: string,
community: string
): AppThunk => async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dispatch
): Promise<void> => {
console.log(
await firebase.firestore().collection(community).doc(docId).get()
);
firebase
.firestore()
.collection(community)
.doc(docId)
.delete()
.then(() => {
console.log("Document successfully deleted!");
dispatch(
alertSuccess("post deleted, reverting to community page", "success")
);
dispatch(retrievePostsByCommunity(community));
})
.catch((error) => {
console.error("Error removing document: ", error);
});
dispatch({ type: DELETE_POST });
};
firebase 规则(这是一个非常简单和基本的设置)
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write, update, delete: if
request.time < timestamp.date(2029, 12, 21);
}
}
}
收藏的图片(如果相关)
解决方案
该方法的参数中的愚蠢错误......设法让它发挥作用。
感谢您的关注!
推荐阅读
- wpf - 数据模板中的 WPF GroupStyle
- php - 无法打开流:连接被拒绝 php
- javascript - 错误:无法编译片段着色器。while slice() 与 Tensorflow.js
- .net - 如何从 Jenkins 中的构建创建工件
- rust - 匹配分支上的 Rust reqwest 调用
- swiftui - SwiftUI 在详细视图中覆盖导航栏外观
- javascript - 如何使用 jQuery/JS 将类添加到非悬停的 div
- unity3d - 团结一致,如何在 NetworkServer.connections 上修复 KeyNotFoundException?
- android - Firebase“.info/connected”怎么了?
- reactjs - 在 Context.Provider 重新渲染中反应导航