Closed ohanspace closed 8 years ago
I am trying to figure out the same thing. I have my list ordered in a certain way using orderByChild:'daysTillDue' and now i want to filter the same list based on a different child property, but still have that list ordered by daysTillDue. How should we go about something like this?
Firebase doesn't allow querying by two children. So what you'll have to do is query by one child and then filter the results on your end. Firebase docs also suggests that you store your data the way you intend to query it, so maybe you need to think of a way to index those records.
@idanen may be right..I didn't find any other way. But it would be great help for developer If the angularfire support this extra feature internally :(
I believe this kind of "feature" will require creating lists above the actual "database", so what they're saying is create it yourself.
You can only query by one field with the Realtime Database.
However you can restructure your data to help.
{
"members": {
"$bloodGroup": {
}
}
}
This way you can get items by
af.database.list('members/A+', {
query: {
orderBy: 'location',
equalTo: 'some place'
}
})
@ohanspace , I know it is a bit late for an answer, but I encountered the same problem and I resolved it by creating a third index :
{ "members" : "uid1" : { "name" : "x", "bloodGroup" : "A+", "location" : "some Place", thirdIndex:"A+//some Place"}, "uid2" : { "name" : "y", "bloodGroup" : "A-", "location" : "some place", thirdIndex:"A-//some Place"}, ... ... }
This is not perfect, but like this you can keep doing the "querying" job by angularFire2 instead of filtering your records in in your front app.
af.database.list('members', { query: { orderBy: 'thirdIndex', equalTo: 'A+//some Place' } })
I have just the same problem and I'll use the filter for now. But it would be very cool, if that would be possible some day, because it could really reduce the size of network transmissions.
+1
@mquentin commented on Oct 31, 2016: this solution is elegant and very userful
Hello Everyone,
I would like to know about multiple query in angularfire2.
my code:
const dcoclublist: AngularFireList
it gives me only data equal true and not both...
any help,it will be appreciated...
Thanks
Please help!!!!
if I have thousands of member records like this. how could I filter them based on
bloodGroup
ANDlocation
and fetching say 100 records from server at a time using angularfire2. As I see querying list only support one parameter inorderByChild
,equalTo
. How could I solve this problem?