Simple search FIREBASE

0

I'm testing on firebase and I'm having trouble recovering bank data with JS. The table structure is as follows:

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

What I want is to return the scores of a given name for example, but I just want to retrieve all the data and manipulate them, I do not want to connect those listeners child_added , child_removed . Is it possible to do this?

I tried this:

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

And I get a firebase object, but I do not know how to manipulate it or even if it is correct.

    
asked by anonymous 05.09.2018 / 18:58

1 answer

1

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

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 lists of items or detect additions to a list of items.

    
05.09.2018 / 23:30