Firebase query

0

I've been using firebase for the first time, and I have a problem. I want to query the database 1x but on my console it appears that it has been queried several times.

        var contador1 = firebase.database() .ref();

    contador1.set({
    Contador: {
      number:1
   }
});

var contando = firebase.database() .ref();

contando.orderByChild("number") .on("child_added", function(data) {
   console.log(data.val() .number);
});

I'm using this code!

In case I wanted to put there variable 1, then it would query in the bank read the variable and add +1

Basically make a counter that works with the database!

    
asked by anonymous 27.09.2017 / 05:39

1 answer

0

The question is not very clear, but from what I realized, you're trying to do something like this:

var contando = firebase.database() .ref().child("Contador/number");

contando.once("value", function(data) {
    var number = data.val();
    console.log(number);
    number++;
    contando.set(number);

});
    
24.02.2018 / 14:02