I\'m looking to get data where two fields equal what I\'m passing in.
Here\'s an example of my code:
this.refApp
.orderByChild(\'u
An other way to do kind of multiple orderByChild
in Firebase is to create an orderKey.
Imagine you have this in your base:
{
userId: {
firstName: 'Snow',
lastName: 'Jon',
birthYear: 283
}
}
And you want to query: userRef.orderByChild('firstName').equalTo('Jon').orderByChild('lastName').equalTo('Snow')
You need to create a key on your user like this:
{
userId: {
firstName: 'Snow',
lastName: 'Jon',
birthYear: 283,
orderName: 'JonSnow'
}
}
So you can query like this: userRef.orderByChild('orderName').equalTo('JonSnow')
This also works with startAt
and endAt
if you want to query all the Snow born in a range of years. You first create the key:
{
userId: {
firstName: 'Snow',
lastName: 'Jon',
birthYear: 283,
orderNameYear: 'Snow283'
}
}
So you can query: userRef.orderByChild('orderNameYear').startAt('Snow280').endAt('Snow285')
This will return all Snow born between 280 and 285.