Map items of collection snapshot in Firebase Firestore

前端 未结 5 381
面向向阳花
面向向阳花 2020-12-24 11:39

Firebase Firestore Guides show how to iterate documents in a collection snapshot with forEach:

db.collection(\"cities\").get().then(function(que         


        
5条回答
  •  一生所求
    2020-12-24 12:05

    // https://firebase.google.com/docs/firestore/query-data/get-data
    const querySnapshot = await db.collection("students").get();
    
    // https://firebase.google.com/docs/reference/js/firebase.firestore.QuerySnapshot?authuser=0#docs
    querySnapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }));
    

提交回复
热议问题