如何通过获取自动生成的ID来删除Firestore中的文档? [英] How to delete a document in firestore by fetching its autogenerated id?

查看:47
本文介绍了如何通过获取自动生成的ID来删除Firestore中的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Firestore中删除文档或子文档如何获取其自动生成的ID,以便在用户长按时在列表中的行项目上选择删除",以便他/她可以轻松地从应用程序的用户界面中删除文档.

How to delete a document or a sub-document in Firestore & how to fetch its auto-generated id so that when the user long presses, selects 'delete' on a row item in the list so that he/she can delete a document from the user interface of the app easily.

推荐答案

现有的随机文档.为了删除文档,您需要执行以下两项操作之一:

You can't "fetch" an existing random document. In order to delete a document you need to do either one of two things:

  • 记住客户端上生成的ID,并使用该ID生成DocumetnReference来删除文档
  • 使用您在该文档中知道的字段来查询文档,然后在查询后将其删除.或者只是查询所有文档,然后将它们作为一个组进行处理.

如果您无法使用文档的字段查询文档,又不知道文档的ID,则说明您很困惑,您将需要更仔细地考虑数据模型.

If you can't query for a document using its fields, and you don't know it's ID, you're kind of stuck, and you will need to think more carefully about your data model.

这篇关于如何通过获取自动生成的ID来删除Firestore中的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆