Getting all documents from one collection in Firestore

前端 未结 8 1920
Happy的楠姐
Happy的楠姐 2020-12-23 15:59

Hi I\'m starting with javascript and react-native and I\'m trying to figure out this problem for hours now. Can someone explain me how to get all the documents from firestor

8条回答
  •  时光取名叫无心
    2020-12-23 16:35

    if you want include Id

    async getMarkers() {
      const events = await firebase.firestore().collection('events')
      events.get().then((querySnapshot) => {
          const tempDoc = querySnapshot.docs.map((doc) => {
            return { id: doc.id, ...doc.data() }
          })
          console.log(tempDoc)
        })
    }
    

    Same way with array

    async getMarkers() {
      const events = await firebase.firestore().collection('events')
      events.get().then((querySnapshot) => {
          const tempDoc = []
          querySnapshot.forEach((doc) => {
             tempDoc.push({ id: doc.id, ...doc.data() })
          })
          console.log(tempDoc)
       })
     }
    

提交回复
热议问题