Do a where in FireBase with Ionic 3

1

I have my DB in firebase but I want to do a where (I know there is no WHERE in a DB NoSQL but there will be some search function), like a login that is if I enter the user and the password brings me the corresponding data of a registration.

  

This is my BD in firebase:

An Example:

  

When I send the email and telefono to tb01_usuario bring me the   corresponding data if the parameters match:

     

Currently I'm doing it only with the ID that is similar to the telephone field, but I need to do it with the two fields that are inside each record, I hope you understand me

verifica_usuario(telefono: string) {

    email = email;
    telefono = telefono;

    let promesa = new Promise((resolve, reject) => {
      //this.items = afDB.list('/cuisines');
      this.af.list('/tb01_usuario/' + telefono)
        .subscribe(data => {
          if (data.length === 0) {
            //clave no es correcta
            resolve(false);
          } else {
            //clave correcta
            this.telefono = telefono;
            this.guardar_storage();
            resolve(true);
          }
        });
    })
      .catch(error => console.log("ERROR en promesa Service: " + JSON.stringify(error)));

    return promesa;
  }
    
asked by Ivan More Flores 05.09.2017 в 15:51
source

1 answer

1

As such, the Where does not exist in Firebase, since the database is in JSON, this means that it is a NoSQL database, where you can only consult based on key = value. You'll find the documentation of the available questions you can ask.

And what you could do, is first get the whole list of users, and then filter with the equalTo function.

this.user = this.af.list('/tb01_usuario/');
this.user.equalTo('email');

On the other hand I tell you that if you manually create the users in the firebase database, you are not generating a ID that firebase assigns to each node when you create the user from an application for example IONIC. Take it into account not be that it causes problems later, also that ID can help you improve your filters or queries.

    
answered by 05.09.2017 в 17:12