英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论