queries do not return null when no data is found

1

I have a question, I am making a query in the first case the data exists in the node and manages to enter .on and recover the data, in the second case the data does not exist in the node so it does not reach to enter a .on and I do not recover any information

liqui
 -KqTiAo1cC0nmASiGr94
    idLiqui: "-KqTiAkEtSrXZHoMo4I2"
    rut: "10401674-k"
    status: "listo"

As seen in the node, I only have 1 data and it is the one that matches the first case, for the second case it does not enter the .on

            vm.settlements.child('liqui')
            .orderByChild('rut')
            .equalTo(employee.rut)
            .on('child_added', function(snapshot){
                 vm.dates = snapshot.val();

            });
    
asked by Luis Ruiz Figueroa 02.08.2017 в 06:45
source

1 answer

0

This is how you do not recover anything, but if you want a callback, to know if there is no match, you can use the function .exists()

{
  "name": {
           "first": "Ada",
          "last": "Lovelace"
    }
}

// Test for the existence of certain keys within a DataSnapshot
var ref = firebase.database().ref("users/ada");
ref.once("value")
 .then(function(snapshot) {
   var a = snapshot.exists();  // true
   var b = snapshot.child("name").exists(); // true
   var c = snapshot.child("name/first").exists(); // true
 var d = snapshot.child("name/middle").exists(); // false
});
    
answered by 03.09.2017 в 04:52