Consultation at Firebase

Asked

Viewed 381 times

0

Guys are using firebase for the first time, and I have a problem. I want to make a query in database 1x but on my console it appears that you have been consulted 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 he would consult in the bank read the variable and add +1

Basically make a counter that works with the database!

1 answer

0

The question is not very clear, but from what I understand, 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);

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.