Label: Firestore Plugin
Desired Outcome:
- Show warning when missing a compound index
- This situation should not result in a double callback (once with data, once without)
Possibly relevant
I was performing the range query on a String field assuming lexicographical ordering (also, the string is of a bastardized date e.g. "2018-06-29")
Background
Using the Flutter Cloud Firestore Plugin, I have run into the 'compound query' issue.
However, to combine the equality operator (==) with a range comparison (<, <=, >, or >=), make sure to create a custom index.
This messages take you to the Managing indexes in Cloud Firestore docs:
If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error. The error message includes a direct link to create the missing index in the Firebase console.
In my case, I saw no such error message or link
My issue
I naively ran into this issue but was confused when I was seeing the handler callback (listening to the query snapshot) was being fired twice. Even stranger is that it first first with the correct data (well, what I assume to be the correct data) and then a second time with an empty list. Thus my flutter application gets a flash of data then poof!
This takes us back to the expected outcome of:
- Can we show the compound index warnings with link to create the correct index
- What's up with the double callback once with the data and then without?
Once I added the compound query (manually on the two fields) everything worked as expected and the handler function was only called once per update.
Below is basically my query (I'm including the wonky date as a string details rather than concealing this terrible truth from the world):
static StreamSubscription streamFooIdsForBar(String barId,
String startDateStr, String endDateStr, onData(List<String> fooIds)) {
return Firestore.instance
.collection(SOME_COLLECTION_CONST)
// equality clause on barId
.where(
'barId',
isEqualTo: barId,
)
// range clauses on a funky date as string...
.where(
'someDateAsString',
isGreaterThanOrEqualTo: startDateStr,
)
.where(
'someDateAsString',
isLessThanOrEqualTo: endDateStr,
)
.snapshots()
.listen((QuerySnapshot query) {
onData(query.documents
.map((DocumentSnapshot doc) => doc.documentID)
.toList());
});
}
Notes
flutter analyze -> nothing
flutter doctor -v
[✓] Flutter (Channel master, v0.5.6-pre.61, on Mac OS X 10.13.5 17F77, locale en-US)
• Flutter version 0.5.6-pre.61 at /Users/ashton/development/flutter/flutter
• Framework revision 2e559584e2 (7 days ago), 2018-06-22 16:32:32 -0700
• Engine revision 549c855e89
• Dart version 2.0.0-dev.63.0.flutter-4c9689c1d2
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/ashton/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.4.1, Build version 9F2000
• ios-deploy 1.9.2
• CocoaPods version 1.5.0
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 25.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[✓] VS Code (version 1.24.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.14.0
[✓] Connected devices (1 available)
• iPhone 5s • 139775FA-03A3-4426-A335-C89AAF2BFA87 • ios • iOS 11.4 (simulator)
• No issues found!
Label: Firestore Plugin
Desired Outcome:
Possibly relevant
I was performing the range query on a String field assuming lexicographical ordering (also, the string is of a bastardized date e.g.
"2018-06-29")Background
Using the Flutter Cloud Firestore Plugin, I have run into the 'compound query' issue.
This messages take you to the Managing indexes in Cloud Firestore docs:
In my case, I saw no such error message or link
My issue
I naively ran into this issue but was confused when I was seeing the handler callback (listening to the query snapshot) was being fired twice. Even stranger is that it first first with the correct data (well, what I assume to be the correct data) and then a second time with an empty list. Thus my flutter application gets a flash of data then poof!
This takes us back to the expected outcome of:
Once I added the compound query (manually on the two fields) everything worked as expected and the handler function was only called once per update.
Below is basically my query (I'm including the wonky date as a string details rather than concealing this terrible truth from the world):
Notes
flutter analyze-> nothingflutter doctor -v