Firestore query subcollections

后端 未结 11 1590
余生分开走
余生分开走 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条回答
  •  我在风中等你
    2020-11-22 09:36

    You can always search like this:-

        this.key$ = new BehaviorSubject(null);
    
        return this.key$.switchMap(key =>
          this.angFirestore
            .collection("dances").doc("danceName").collections("songs", ref =>
              ref
                .where("songName", "==", X)
            )
            .snapshotChanges()
            .map(actions => {
              if (actions.toString()) {
                return actions.map(a => {
                  const data = a.payload.doc.data() as Dance;
                  const id = a.payload.doc.id;
                  return { id, ...data };
                });
              } else {
                return false;
              }
            })
        );
    

提交回复
热议问题