首页 > 解决方案 > 使用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);
    }
  }
} 

收藏的图片(如果相关)

谢谢! https://i.stack.imgur.com/UfRhm.png

标签: reactjstypescriptgoogle-cloud-firestorefirebase-securityredux-thunk

解决方案


该方法的参数中的愚蠢错误......设法让它发挥作用。

感谢您的关注!


推荐阅读