Getting all documents from one collection in Firestore

前端 未结 8 1925
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:36

    You could get the whole collection as an object, rather than array like this:

    async getMarker() {
        const snapshot = await firebase.firestore().collection('events').get()
        const collection = {};
        snapshot.forEach(doc => {
            collection[doc.id] = doc.data();
        });
        return collection;
    }
    

    That would give you a better representation of what's in firestore. Nothing wrong with an array, just another option.

提交回复
热议问题