0

This is how I have my database structured:

enter image description here

The following checks if flight MK2345 exists

fbSearch: function(){
                var key;
                var childData;              
                firebase.database().ref('/flights/').orderByChild("flight").equalTo('MK2345').on('value', function (snapshot) {
                    if (snapshot.exists()){
                        snapshot.forEach(function(childSnapshot) {
                            key = childSnapshot.key;
                            childData = childSnapshot.val();
                            console.log(childSnapshot.key)
                        });
                    }else{
                        console.log('not existing')
                    }
                })              
            }

but I want it to check if the combination flight date and origin exists. As example: I'd like to check if the following combination exists: Date: 2019/07/23 Flight: MK1234 origin: AMS

MK01111000
  • 770
  • 2
  • 9
  • 16
  • 1
    Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. So in your case something like `"origin_date": "AMS_2019/07/24"` (my favorite airport btw ). For a longer example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jul 27 '19 at 02:55
  • Thanks Frank, that was the information I was looking for! – MK01111000 Jul 27 '19 at 11:26

0 Answers0