'Missing documents from firestore
I have a flutter app in development and I use firestore as the storage. users (collections)-> userId(doc) -> records (collection)
I am using this query:
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records')
I notice when I test my app on simulator and test on my physical iphone, the list of documents I get from firestore are different. And on both env, I notice there are some documents are missing when I fetch from firestore. I can see the documents are in the firestore, but when I check the result of the query, I couldn't get the full list of documents in the collection. I notice I can only get the newly added documents. But the older documents, I couldn't get them anymore. Anyone know where to start to debug this issue? Thanks.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
I checked the query exception, no exception detected, the query succeeded.
Solution 1:[1]
Found out that the way I read from firebase has some problems. I was using this to read from the subcollection:
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').snapshots()
which returns a stream and I didn't listen to it properly.
Changed to
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').get()
which returns a future, and using await to wait this future. Now it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Liping Xiong |
