删除 Firestore 文档,无需知道集合名称。

huangapple go评论90阅读模式
英文:

Delete a firestore document without knowing the collection

问题

我知道文档ID,但不知道集合ID。我可以使用集合组查询找到文档,但是否有类似的方法来删除它?

更确切地说,我有帖子,帖子有评论。出于架构原因,我希望能够在不知道帖子ID的情况下删除评论。

英文:

I know the document Id, but i don't know the collection Id. I can find the document using a collectionGroup query, but is there a similar way to delete it?

To be more exact I have posts, that have comments. For architectural reasons I want to be able to delete a comment without knowing the post Id.

答案1

得分: 1

要删除文档,您需要能够构建一个完全唯一的路径。在API术语中,这被称为DocumentReference。如果您不知道集合名称,那么您就无法构建对它的引用,因此也无法删除它。如果您唯一识别文档的方法是通过集合组查询,那么这就是您必须做的事情。

英文:

In order to delete a document, you be able to build a full unique path to it. In API terms, that is called a DocumentReference. If you don't know the collection name, then you can't build a reference to it, therefore you can't delete it. If your only way of identifying a document is by a collection group query, then that's what you'll have to do.

huangapple
  • 本文由 发表于 2023年6月9日 04:57:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76435644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定