I am creating a leaderboard app using Firebase as the database. I come from an old school SQL background so this new noSQL type of databasing is giving me database key and reference anxiety.
If I have groups, each groups having members, and then all the users have scores for various tests, what is the most efficient way of getting the data for a group where the scores of a given test are displayed in order. In SQL this is obviously trivial using joins and then orderby but so far in the firebase docs I can't workout how to efficiently query to get blocks of joined data without having some of the sorting work on the client side
my current solution is, given below but it seems painful to have to do all the sorting on the client side. I currently get all the users for the group, and then iterate to get the individual records of test scores for each user. I need to get the single highest score for a given test, regardless of date.
var testName = 'test1';
var scores = firebase.database().ref('/groupMembers/' + 'TestGroup').once('value').then(function(snapshot) {
console.log(snapshot.val());
for(var user in snapshot.val()){
//...query the database for each separate users score on test1
}
//sort the test scores here on client side js
});
Any tips of the database design won't go amiss either!
groupMembers{
TestGroup{
user1 : true
user2 : true
}
}
testScores{
user1{
test1{
date : 11/04/2016
score : 90
}
test1{
date : 05/07/2016
score : 100
}
test2{
date : 11/06/2016
score : 50
}
}
user2{
test1{
date : 15/04/2016
score : 70
}
test2{
date : 05/07/2016
score : 80
}
test2{
date : 11/10/2016
score : 50
}
}
}
Thanks