Firestore 查询子集合 [英] Firestore query subcollections

查看:38
本文介绍了Firestore 查询子集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我读到您可以使用新的 Firebase Firestore 查询子集合,但我没有看到任何示例.例如,我的 Firestore 设置如下:

I thought I read that you can query subcollections with the new Firebase Firestore, but I don't see any examples. For example I have my Firestore setup in the following way:

  • 舞蹈[集合]
    • 舞蹈名称
    • 歌曲[合集]
      • 歌曲名称

      我如何才能查询查找歌曲名称 == 'X' 的所有舞蹈"

      How would I be able to query "Find all dances where songName == 'X'"

      推荐答案

      更新 2019-05-07

      今天我们发布了集合组查询,这些允许您跨子集合进行查询.

      Today we released collection group queries, and these allow you to query across subcollections.

      因此,例如在 Web SDK 中:

      So, for example in the web SDK:

      db.collectionGroup('Songs')
        .where('songName', '==', 'X')
        .get()
      

      这将匹配集合路径的最后一部分是歌曲"的任何集合中的文档.

      This would match documents in any collection where the last part of the collection path is 'Songs'.

      您最初的问题是关于找到 dances where songName == 'X',但这仍然无法直接实现,但是,对于匹配的每首歌曲,您都可以加载其父歌曲.

      Your original question was about finding dances where songName == 'X', and this still isn't possible directly, however, for each Song that matched you can load its parent.

      原答案

      这是尚不存在的功能.它被称为集合组查询",它允许您查询所有歌曲,而不管包含它们的舞蹈.这是我们打算支持但没有具体时间表的事情.

      This is a feature which does not yet exist. It's called a "collection group query" and would allow you query all songs regardless of which dance contained them. This is something we intend to support but don't have a concrete timeline on when it's coming.

      此时的替代结构是使歌曲成为顶级收藏,并使歌曲成为歌曲属性的一部分.

      The alternative structure at this point is to make songs a top-level collection and make which dance the song is a part of a property of the song.

      这篇关于Firestore 查询子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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