【问题标题】:how to select specific user documents from a collection?如何从集合中选择特定的用户文档?
【发布时间】:2022-12-18 22:22:17
【问题描述】:

我有一个 idea firestore 集合,其中存储了不同用户的文档,如何选择特定用户的所有文档并删除?

我需要添加删除帐户按钮,按下后,用户的所有信息都被删除了。

FirebaseFirestore.instance.collection('ideas').get().then(
            (value) {
              value.docs.forEach((result) {
                print(result.data()[email!]);
              });
            },
          );

【问题讨论】:

    标签: flutter firebase google-cloud-firestore


    【解决方案1】:

    这取决于创意文档如何与特定用户相关联。如果文档中的字段(例如user)带有用户的 UID,您可以使用 use a query 获取特定用户的文档:

    // Create a reference to the cities collection
    final ideasRef = db.collection("ideas");
    
    // Create a query against the collection.
    final query = ideasRef.where("user", isEqualTo: "uidOfTheUser");
    

    然后你execute the query 得到它的结果。

    【讨论】:

      猜你喜欢
      • 2020-05-07
      • 2017-04-28
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      相关资源
      最近更新 更多