Reputation: 1
can anyone help me structure this query everything works but as soon as I put the age range query it throws an error here's my query
fireStore
.collection('TestUsers')
.where('Country', isEqualTo: 'Mexico')
.where('ID', whereNotIn: [
'9f8fe3c0-83fb-11ec-ba7d-71eedc0beebe',
'3eb69ae0-83fa-11ec-b4a4-cba7e6a8918b'
])
.orderBy('ID', descending: true)
.where('DOB',
isLessThan: minAgeToQueryWith,
isGreaterThan: maxAgeToQueryWith)
.orderBy('DOB', descending: true)
.where('Gender', isEqualTo: 'Gender Fluid')
.orderBy('BoostDate', descending: true)
.orderBy('Points', descending: true),
this is the error I get
The initial orderBy() field '[[FieldPath([ID]), true]][0][0]' has to be the same as the where() field parameter 'FieldPath([DOB])' when an inequality operator is invoked. 'package:cloud_firestore/src/query.dart': Failed assertion: line 677 pos 11: 'field == orders[0][0]'
Upvotes: 0
Views: 928
Reputation: 197
Here is the solution. You must use .orderBy for the .where query
For Example
_firestore
.collection(_generalNotifications)
.where('isDeleted', isNotEqualTo: true)
.orderBy('isDeleted')
.orderBy('sentAt', descending: true)
.snapshots()
So here is your correction.
fireStore
.collection('TestUsers')
.where('Country', isEqualTo: 'Mexico')
.where('ID', whereNotIn: [
'9f8fe3c0-83fb-11ec-ba7d-71eedc0beebe',
'3eb69ae0-83fa-11ec-b4a4-cba7e6a8918b'
])
.where('DOB',
isLessThan: minAgeToQueryWith,
isGreaterThan: maxAgeToQueryWith)
.where('Gender', isEqualTo: 'Gender Fluid')
.orderBy('Gender')
.orderBy('DOB', descending: true)
.orderBy('ID', descending: true)
.orderBy('BoostDate', descending: true)
.orderBy('Points', descending: true),
Upvotes: 2
Reputation: 5
You need to put where
in the first and the orderby
in the last
solution is
fireStore
.collection('TestUsers')
.where('Country', isEqualTo: 'Mexico')
.where('ID', whereNotIn: [
'9f8fe3c0-83fb-11ec-ba7d-71eedc0beebe',
'3eb69ae0-83fa-11ec-b4a4-cba7e6a8918b'
])
.where('DOB',
isLessThan: minAgeToQueryWith,
isGreaterThan: maxAgeToQueryWith)
.where('Gender', isEqualTo: 'Gender Fluid')
.orderBy('BoostDate', descending: true)
.orderBy('Points', descending: true)
.orderBy('ID', descending: true)
.orderBy('DOB', descending: true)
it must work , but if the fields of orderBy does not equal in logic then you need to put only one .orderBy query
Upvotes: 0