I am using Firestore in my Flutter app. When I query a collection, I am getting the incorrect number of documents back.
The correct number of documents I should be getting back for my query is 20.
If I initialise Firebase as follows...
await Firebase.initializeApp();
FirebaseFirestore.instance.settings = Settings(persistenceEnabled: true);
I get only 2 documents back from my query.
If I initialize Firebase with peristenceEnabled false...
await Firebase.initializeApp();
FirebaseFirestore.instance.settings = Settings(persistenceEnabled: false);
I am wondering if it has to do with the fact I am only grabbing the first event in the stream. My query is as follows...
static Future<List<String>> myQuery(String personId , String bagId , String batchId , List<String> items) async {
var db = FirebaseFirestore.instance;
var q = db.collection('people')
.doc(personId)
.collection('bags')
.doc(bagId)
.collection('batches')
.where('batchId', isEqualTo: batchId)
.where('itemId', whereIn: items)
.where('status', isEqualTo: 'active');
var stream = q.snapshots().map((snapshot) {
List<String> results = [];
for (var doc in snapshot.docs) {
results.add(doc.id);
}
return results;
});
return stream.first;
}
}
If persistence is enabled this method returns a list of incorrect length. If persistence is disabled, this returns a list of the correct length.
I would expect the built in firestore caching mechanism would be smart enough to detect that any cached data is stale. I am therefore wondering if there is something wrong with my firestore data in general, such that it is breaking client side persistence/caching.