I'm building a React Native app with Expo using the Firebase web api and trying to retrieve a collection of documents from my Firestore project. According to the documentation over at https://firebase.google.com/docs/firestore/query-data/get-data I should be able to iterate over a collection using the forEach() method provided by the collection snapshot like so:
db
.collection('services')
.get()
.then(snapshot => {
snapshot.forEach(doc => {
if (doc && doc.exists) {
console.log(doc.id, ' => ', doc.data());
}
});
});
This however only logs one document, despite the fact that I currently have 3 documents in the collection, what am I missing? Please help.
My firebase config looks like so:
import * as firebase from 'firebase';
firebase.initializeApp({
"projectId": "my-project-id",
"apiKey": "my-api-key",
"authDomain": "my-project.firebaseapp.com",
"databaseURL": "https://my-project.firebaseio.com",
"storageBucket": "my-project-id.appspot.com/",
"messagingSenderId": "my-messaging-sender-id"
})
const db = firebase.firestore();