Using Firebase query in Ionic


#1

I have my firebase structure like this…
There are number of keys like this .

I am displaying my data like this in a table-

How can I use firebase query to search and fetch the details according to train name,Arrival time ,like this.
Any help in this regard would be appreciated…

My .ts file code-

 showdata()
   {
       this.searchtrainno().on('value', snapshot => {
      this.trainList = [];
      snapshot.forEach( snap => {
        this.trainList.push({
          id: snap.key,
          Arrivaltime:snap.val().Arrivaltime,
          Departuretime:snap.val().Departuretime,
          DestinationStationName:snap.val().DestinationStationName,
          DestinationstationCode:snap.val().DestinationstationCode,
          Distance:snap.val().Distance,
          islno:snap.val().islno,
          sourceStationName:snap.val().sourceStationName,
          SourceStationCode:snap.val().SourceStationCode,
          StationName:snap.val().StationName,
          stationCode:snap.val().stationCode,
          trainName:snap.val().trainName,
          TrainNo:snap.val().TrainNo


        }); 
     

    
        return false
      });

       
 
 
    });   
 
   
   }

searchtrainno()
{
  
  console.log( this.userProfileRef.orderByValue().startAt('00851').endAt('00851'));
 
 return this.userProfileRef.orderByValue().startAt('00851').endAt('00851');
 
}

I am not getting any output on running this,and
On console.log I am getting value-

X {u: Qg, path: E, m: lf, Nc: true}
Nc
:
true
m
:
lf {xa: false, ka: true, Kb: false, na: true, Rb: false, …}
path
:
E {o: Array(0), Y: 0}
u
:
Qg {app: FirebaseAppImpl, L: zb, Va: Lf, Vc: null, ca: Ye, …}
ref
:
(…)
proto
:
Object


#3

I think this is what you want:

this.searchtrainno().orderByChild('TrainNo').equalTo('00851').once('value', snapshot => {

  if (snapshot.val()) {

    return snapshot.val();

  } else {

    // the TrainNo 00851 does not exist

  }

})

#4

have you solved it?
Now I am facing the problem which is generating the WHERE clause in Firebase.
How can I convert this SQL query "SELECT * FROM customer-list WHERE key=“xxxxxxx” "; into Firebase Query.

PLEASE HELP!!! (I am using Angular2Fire)


#5

Switch over to Firestore. Queries are based on WHERE-type clauses