Home > Back-end >  Firestore compound query not working flutter
Firestore compound query not working flutter

Time:06-15

I have a problem using compound query in firebase flutter, the following query:

int priceMax, priceMin;
String product;
searchQuery =  FirebaseFirestore.instance.collection("Products")
        .where("price", isLessThanOrEqualTo: priceMax)
        .where("price", isGreaterThanOrEqualTo: priceMin)
        .orderBy("price")
        .orderBy("name")
        .startAt([product])
        .endAt([product '\uf8ff']);

When I make a query with price only it works right and when I make for product only it also works but when I make both together it doesn't give any results or errors.

Please note that I created index at firestore indexes for this query.

this is error log:

D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_UP, id[0]=0, pointerCount=1, eventTime=180673922, downTime=180673883 } moveCount:1
I/Counters(20223): exceeded sample count in FrameTime
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_DOWN, id[0]=0, pointerCount=1, eventTime=180675337, downTime=180675337 } moveCount:0
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_UP, id[0]=0, pointerCount=1, eventTime=180675472, downTime=180675337 } moveCount:17
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_DOWN, id[0]=0, pointerCount=1, eventTime=180676056, downTime=180676056 } moveCount:0
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_UP, id[0]=0, pointerCount=1, eventTime=180676101, downTime=180676056 } moveCount:0
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_DOWN, id[0]=0, pointerCount=1, eventTime=180677640, downTime=180677640 } moveCount:0
D/MIUIInput(20223): [MotionEvent] ViewRootImpl { action=ACTION_UP, id[0]=0, pointerCount=1, eventTime=180677734, downTime=180677640 } moveCount:0
I/Counters(20223): exceeded sample count in FrameTime

Can anyone help me with this? Thanks

CodePudding user response:

You're trying to run a query with two relational conditions on two fields, which is not supported in Firestore. According to the query limitations in the documentation:

If you include a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field

While it doesn't explicitly name them, the startAt startAfter, endAt and endBefore operators also are considered range operators.

  • Related