【问题标题】:Firebase query to perform posts search Cloud Firestore [duplicate]Firebase 查询以执行帖子搜索 Cloud Firestore [重复]
【发布时间】:2021-11-12 13:21:57
【问题描述】:
  1. 我有posts(collection) -> userid(document) -> userposts(collection) -> postid(document) -> fields (postname,description)。 如何根据 postname 执行搜索?我想从所有用户那里获得帖子。

  2. 我有追随者和追随者收藏 following -> userid(document)->userfollowing (collection) -> all the user ids(documents)followers -> userid(document)->userfollowers (collection) -> all the user ids(documents).

我有一个时间线页面,当前登录的用户应该能够看到他关注的用户的所有帖子。

如果这不正确,我准备更改结构。

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    您可以将collectionGroup 查询与where() 一起使用:

    final query = Firestore.instance
            .collectionGroup('posts')
            .where('postname', isEqualTo: 'post_name_to_search')
    

    这将从posts 的所有用户子集合中返回与提供的名称匹配的文档。

    【讨论】:

    • 你能再检查一下我已经编辑过的问题吗
    • @PranathNaik 我看到了你发布的其他问题,看起来很相似。我会尽快回来的。
    猜你喜欢
    • 2018-03-20
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2018-06-22
    • 2019-04-22
    • 2022-10-17
    相关资源
    最近更新 更多