2

I have my firebase db like this

    "students" : {
        "-LDD0MIigieZQ3Fcaj1Z" : {
          "ContactNo" : "0752155466",
          "Email" : "[email protected]",
          "FirstName" : "Ishana",
          "Gender" : "Female",
          "LastName" : "Dahanayake",
          "Password" : "1234",
          "score" : 6
        },
        "-LDD0ceFiy2RI1avfMWA" : {
          "ContactNo" : "0752155466",
          "Email" : "[email protected]",
          "FirstName" : "Ruwan",
          "Gender" : "Male",
          "LastName" : "Perera",
          "Password" : "1234",
          "score" : 1
        }
      }

I need to sort these students by score

i tried like this

    let ref = this.afDB.list('/students',ref=>ref.orderByChild('score')).snapshotChanges()
        .map(changes =>{
          return changes.map(c=> ({key:c.payload.key,...c.payload.val()}));
        });
    
        return ref;

but its not changing the order according to the score value.How can i sort these values?

4

1 Answer 1

1

If this code you wrote :

    let ref = this.afDB.list('/students',ref=>ref.orderByChild('score')).snapshotChanges()
        .map(changes =>{
          return changes.map(c=> ({key:c.payload.key,...c.payload.val()}));
        });
    
        return ref;

returns you values you need to sort, i would just add return ref.sort();

Sign up to request clarification or add additional context in comments.

1 Comment

Yes it is working thing is when we need to sort by a number uploading value should be a number.Not a string.That's it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.