I’m trying to query my data to retrieve a list of items sorted alphabetically and filtered by those items marked as “visible”.
Here’s my data structure.
listItems
list_1_uid
item_1_uid
name: "Item 01"
nameLowercase: "item 01"
visible: true
item_2_uid
name: "zItem 02"
nameLowercase: "zitem 02"
visible: false
item_3_uid
name: "aItem 03"
nameLowercase: "aitem 03"
visible: true
Here’s my query.
mQuery = mFirebaseDbReference
.child("listItems")
.child("list_1_uid")
.orderByChild("nameLowercase")
.equalTo(true, "visible");
My query returns no data. If I remove the .equalTo(true, "visible") statement the query returns my entire alphabetized list.
Any suggestions on how to retrieve my filtered list?
Queries in Firebase are tied to property specified in the orderBy
call. Therefore the equalTo(boolean value, String key)
call in this example refers to nameLowercase
, so it will query for all items with nameLowercase
set to true
. The second parameter refers to the key of the item (e.g. item_1_uid
) and can be used to specify a starting point in the query. This is useful for paginating through the results for example.
Since there is no limit on this query, a solution would be to use a query that orders by "visible" and then do any additional sorting on nameLowercase
client side with the final result:
mQuery = mFirebaseDbReference
.child("listItems")
.child("list_1_uid")
.orderByChild("visible")
.equalTo(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With