Firestore query subcollections

后端 未结 11 1503
余生分开走
余生分开走 2020-11-22 09:24

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

11条回答
  •  萌比男神i
    2020-11-22 09:49

    Update 2019-05-07

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

    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'.

    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.

    Original answer

    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.

提交回复
热议问题