Simple search FIREBASE

Asked

Viewed 396 times

0

I’m doing a test on firebase and I’m having a hard time retrieving the data from the JS database. The structure of the table is as follows:

Scores
    - key
        - name
        - points
    - key
        - name
        - points

What I want is to return the colors of certain name for example, but I just want to recover all the data and manipulate them, I do not want to connect those listeners child_added, child_removed. It is possible to do this?

I tried that:

firebase.database().ref('scores').orderByChild('name').equalTo('Fulano');

And returns me an object from firebase, but I do not know how to manipulate it and whether this search is correct.

1 answer

1


As you can see best in this link (documentation), to work with the data returned by firebase it is necessary to use the function .on(), which receives an event and a function, which will be executed as the data is being recovered.

let consulta = firebase.database().ref('scores').orderByChild('name').equalTo('Fulano');
consulta.on('child_added', function(data) {
    console.log(data.val().name);
    console.log(data.val().points);
});

Being 'child_added' an event to retrieve item lists or detect additions to an item list.

Browser other questions tagged

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