My Firebase Array has the following structure:
[
{
'userId': '12345',
'itemOrdered' : 'abc',
'status': 'pending'
...other attributes
},
{
'userId': '6789',
'itemOrdered' : 'def',
'status' : 'pending',
...other attributes
},
{
'userId': '12345',
'itemOrdered' : 'def',
'status' : 'complete',
...other attributes
},
]
I am not able to figure out how to retrieve the following data:
- Get records with userId = xxx
- Get all records where 'itemOrdered" = 'def'
Firebase docs talk about using orderByChild but that doesn't make much sense.
Assuming you're using the JavaScript SDK to access Firebase:
ref.orderByChild('userId').equalTo('xxx')
ref.orderByChild('itemOrdered').equalTo('def')
If you're trying to build a query that gets order of item
def
from userxxx
, then that's not currently possible with Firebase's querying. The only way to query the value of multiple properties is to combine them in a single property in a way that allows the query you want. E.g.ref.orderByChild('userId_itemOrdered').equalTo('xxx_def')