Description
Version info
Angular: 7.2.5
Firebase: 5.8.3
AngularFire: 5.1.1
Other (e.g. Ionic/Cordova, Node, browser, operating system): node 10.14.2, macOs X
How to reproduce these conditions
I've had some trouble isolating the exact problem. Basically, I have a people
collection. If I fetch an individual document from the people collection (lets call it the person A doc), and then subscribe to the entire people collection, I'm seeing that the collection('people').valueChanges()
subscription immediately returns an array that just contains person A. The subscription then fires again shortly later with the full results of the person collection.
If I invoke collection('people').valueChanges()
before fetching an individual document from the people
collection, then collection('people').valueChanges()
returns the correct results on the first try.
What I think is happening, is that collection('people')
is immediately returning results from an in-memory cache and then updating those results when it hears back from the server. I could see scenarios where this behavior would be desirable, but it is not desirable in my case, was unexpected and hard to diagnose, and there doesn't seem to be an option to disable it. I'm not sure if this is intended behavior or a bug.
I think it's possible that issue #1975 is being caused by the same problem.
In my case, the problem with this behavior (other than the fact that it is unexpected) is that I want to take(1)
from the collection('people').valueChanges()
query, except now the return value of that action is indefinite.
Debug output
I have none. I did try to set firebase.database().enableLogging(true);
as suggested, but this.angularFirestore.app.database()
does not have an enableLogging()
function.
Expected behavior
By default, I expected query results to not be returned unless they accurately reflect the query.
I could see value in returning results immediately from a cache, but I don't think this behavior should be the default as it's unexpected, hard to diagnose, and can lead to unwanted behavior.
Actual behavior
AngularFirestore#collection()
seems to return results immediately from the cache and then update the results when it hears back from the server.