Reputation: 1
I am trying to get data from the end nodes of firebase, but I am not sure how to query correctly using Firebase /node.js
My database looks like this:
Database -> User (i.e. Greg, Mike, etc.) -> Randomly Generated String (i.e. XKJFJ34234KSDF) -> General Info (Age, Height)
I do not know the randomly generated string for a user so I do not know how to get the age for everyone.
A sample output looks like this
{ 'Greg':
{ '-KQwvifPzq6g1JnRPYZn':
{ Age: 188,
Height: 6.1
}
}}
Upvotes: 0
Views: 87
Reputation: 28750
You need to flatten your data more, your key should not be greg but instead the generated one you posted. Greg itself should be a property of that user.
{
User: {
'-KQwvifPzq6g1JnRPYZn' : {
Name : 'Greg',
Age : 188,
Height : 6.1
},
...
},
...
}
So that you can write queries like so:
firebase.database().ref().child('user').orderByChild('Age').startAt(180).endAt(190)
firebase.database().ref().child('user').orderByChild('Age').equalTo(188)
Upvotes: 1