Firebase Sorting Data Retrieval
This is the code that I have: I am trying to get data stored in the Firebase Database sorted by wage. The order of the database goes: 'Posts -> PostID(.push when saving) -> W
Solution 1:
You're storing the wages as string, which means that they will be sorted in lexicographical order:
1
13
2
20
3
If you want to get the results in numerical order, you should store the wages as numbers, so without the quotes.
If you store them from your code, this might require that you convert it with parseInt(wagesAsString)
.
After you store the wages as numbers, you can get them in order with:
var PostsRef = firebase.database().ref().child("Posts");
var query = PostsRef.orderByChild("wage");
query.on('child_added', function(data) {
Post a Comment for "Firebase Sorting Data Retrieval"