[Fixed] How to get all documents from Firestore in once?

Issue

When I subscribe to valueChanges I first get back an object of length 1, as you can see in console.log (picture below), and a short time later the object with all values. But this is not what I wanted. I need go get all values from the beginning so that I can continue to work with these. Can somebody help? Thanks.

return new Promise(resolve => {
   this.store.collection('Kontaktdaten',ref => ref.where('Ankunft', '>=', timeAnkunft))
        .valueChanges()
        .subscribe((persons) => {
          personsArray = persons;
          console.log(personsArray)
          personsArray.map((person,index,array) => {
            if(person.Ende > timeEndeBesuch) {
              array.splice(index,1);
            }
          })
          resolve(personsArray);   
        })
    })

Solution

Did you enable disk caching by any chance? If so, it is likely that the initial result comes from the local cache.

There isn’t really a way to prevent this, but you can detect that the item comes from the local cache and may be stale by checking its DocumentSnapshot.metadata.fromCache property.

Leave a Reply

(*) Required, Your email will not be published