How can I link the leaderboards with other collections but not by scoreid?

0 votes

Hi,

I'm setting up the leaderboard in our game but we noticed that if we save addtional leaderboard information in a storage service collection it's linked by the scoreid, can we query based in the user field? as in our case we are saving the facebook, game center and google play services ID in that field and the nickname or username in the storage collection.

So this is currently the structure

Leaderboard1

User Score ScoreId
10001 500 1
10001 200 2

Leaderboard2

User Score ScoreId
10001 100 3
10002 300 4

Storage Service Collection(Document)

ScoreId Username Nickname
1 TestUser1 Test1
2 TestUser1 Test1
3 TestUser1 Test1
4 TestUser2 Test2


In this case there is unnecessary repeated information, what we want is this:

Storage Service Collection(Document)

User UserName Nickname
10001 TestUser1 Test1
10002 TestUser2 Test2

 

this is important for us because we setup the app having many leaderboards(games) but the additional information is shared using the same storage service collection(which for us is like a user table), is there a way to fetch that data using the user instead of the automatic scoreid link field?

Thanks

Omar

asked Jan 8, 2015 in App42 Cloud API-BaaS by ochapa (15 points)

1 Answer

0 votes
 
Best answer

Hello Ochapa,

 
Yes, you can find it easily using query interface along with leaderboard call. Kindly have a look at this link for the code snippet.
 
Also if you want to fetch all the document related to that user, you can fetch it easily by putting the query as a "null" in the setQuery method as shown in the below code snippet.
 
scoreBoardService.setQuery("<Your_Collection_Name>", null);
 
It will return all the document related to that user in leaderboard object. Please check & let us know if you have more questions for us.
 
Thanks,
Himanshu Sharma
answered Jan 8, 2015 by hs00105 (2,005 points)
selected Jan 9, 2015 by ochapa
Hi Himanshu,

I'm using currently that code to link the tables and it does work in the default form by adding
a json object to the saveuserscore function and internally linking the table by scoreid, but if I
create the table manually it does not link the fields properly

this is a test score from a user:

Leaderboard 1
userName: 1369292960
score 100

this is what is saved in the collection using this code

Dictionary<string, object> jsonDoc = new Dictionary<string, object> ();              jsonDoc.Add(USERDISPLAYNAMEFIELD,userDisplayName);    
jsonDoc.Add(ISFACEBOOKUSERFIELD,isFacebookUser);

App42API.SetDbName(DBNAME);   
scoreBoardService.AddJSONObject(LEADERBOARDDATACOLLECTION, jsonDoc);
scoreBoardService.SaveUserScore(LeaderboardId, userName, score, new callback())

and the json generated in the collection is this:
{"_$scoreId":"bpBgUMmhApK+b+RhWcLsHJ8QzNk=","userDisplayName":"Omar","isFacebookUser":true}

but if I save the user collection separately and having the resulting json:
{"userName":"1369292960","userDisplayName":"Omar","isFacebookUser":true}

and when I execute the this code:

App42API.SetDbName(DBNAME);  
scoreBoardService.SetQuery(LEADERBOARDDATACOLLECTION,null);
scoreBoardService.GetTopNRankers(leaderboardId,maxUsers,new callback());   

it doesn't link the query by the userName and because of that it returns 0 documents using

game.GetScoreList()[i].GetJsonDocList().Count

It only returns the userName and score from the leaderboards but not the additional data

but if I save normally through
scoreBoardService.AddJSONObject(LEADERBOARDDATACOLLECTION, jsonDoc);
scoreBoardService.SaveUserScore(LeaderboardId, UserId, Score, new callback())

it returns the right values but with the repeated data problem that I explained in the first post by linking the user additional data with a scoreid and having multiple leaderboards it causes this collection to have unnecessary repeated data for each score in each leaderboard

Can you help me with this issue?

Thanks
Omar
Hello Omar,

In such case, you can easily link this information by setting owner of that document. For example: You are saving an information in storage service where JSON document is :  {"userName":"1369292960","userDisplayName":"Omar","isFacebookUser":true}
and you need to link this information with user (1369292960) in leaderboard. By using the below code snippet while inserting the json document in storage:

App42API.setLoggedInUser("1369292960");

Please check & let us know if it helps.
Thanks that worked!

By setting the App42API.setLoggedInUser("your id") I could retrieve the data properly in the querys
Great to hear that your query has been resolved, let us know if you have more questions for us.
Thanks,
Himanshu Sharrma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...