【问题标题】:Get all documents from collection in firestore从firestore中的集合中获取所有文档
【发布时间】:2019-10-16 21:25:59
【问题描述】:

我正在尝试从我的“instagram”克隆应用中获取所有帖子。这是我在 Firestore 中的路径:posts > (unique ownerId) > userPosts > (unique postId)

如何使用流生成器检索所有帖子?我试过这样做

body:
StreamBuilder<QuerySnapshot>(
          stream: postsRef.snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) {
              return circularProgress();
            }
            List<Post> posts = snapshot.data.documents.map((doc) =>  Post.fromDocument(doc)).toList();
            return ListView(children: posts);
          },
        )

我只想在一堆卡片中显示帖子的图片。

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    您不能在 Cloud Firestore 中对侦听器使用通配符。您需要命名路径中的特定文档和集合。因此,如果在查询时您的(unique ownerId) 未知,您将无法知道其子集合中更改的文档的任何信息。

    作为替代方案,在您控制的后端,您可以list subcollections 的文档,然后查询这些文档。或者,您可以使用 Cloud Functions 触发器并在发生更改时通知感兴趣的客户端应用程序(可能使用 Cloud Messaging)。

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 2021-07-29
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2021-07-01
      • 2021-05-09
      相关资源
      最近更新 更多