Firestore query documents with only collections inside

后端 未结 2 1772
不思量自难忘°
不思量自难忘° 2021-01-22 19:59

I have a firestore collection which has some documents inside it. The documents contains only collections not any fields. So when I try to get all documents inside the root coll

相关标签:
2条回答
  • 2021-01-22 20:11

    Adapted from Get Data with Cloud Firestore

    db.collection("transactions").doc("2018-01-02").collection("education-1").get()
        .then(function(querySnapshot) {
            querySnapshot.forEach(function(doc) {
                // doc.data() is never undefined for query doc snapshots
                console.log(doc.id, " => ", doc.data());
            });
        })
        .catch(function(error) {
            console.log("Error getting documents: ", error);
        });
    
    0 讨论(0)
  • 2021-01-22 20:16
    let date = '2017-12-20' //date to be set in doc
    
    db.collection("transactions").doc(date).set({
      //set an empty object for each doc in transaction before your method 
      //of setting data 
      //This will create a field for each doc in transaction
    })
    .then(()=>{
      //your method of setting data here.
    })
    //Your query method here.
    //Now you will be able to query the docs in collection - transaction.
    
    0 讨论(0)
提交回复
热议问题