Filter for a specific record in Firebase

Viewed 57

I've this structure of Fire Database

enter image description here

If I need to find a specific box, I do in Angular

url = 'https://box-xxxyyy.firebaseio.com';

  getBox( box: string) {

    return this.http.get<any>(`${ this.url }/box/${ box }.json`)
      .pipe(
        map( res => {
          return res;
         } )
      );

  } 

But if I need to find all the records that have "red" in the "color" field, how i do?

1 Answers

If you follow the documentation on filtering data, you might come up with a query like this, using orderBy and equalTo query string parameters:

this.http.get<any>(`${ this.url }/box/${ box }.json?orderBy="color"&equalTo="red"`)
Related