Firestore query subcollections

后端 未结 11 1393
余生分开走
余生分开走 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:39

    var songs = []    
    db.collection('Dances')
          .where('songs.aNameOfASong', '==', true)
          .get()
          .then(function(querySnapshot) {
            var songLength = querySnapshot.size
            var i=0;
            querySnapshot.forEach(function(doc) {
               songs.push(doc.data())
               i ++;
               if(songLength===i){
                    console.log(songs
               }
              console.log(doc.id, " => ", doc.data());
            });
           })
           .catch(function(error) {
             console.log("Error getting documents: ", error);
            });
    

提交回复
热议问题