How would I get this data out of the database?

0 votes

http://imgur.com/ALbWg4A

App42API.setLoggedInUser(user.getUserName()); 

storageService.findDocumentByKeyValue(dbName, userName, "Losses", new App42CallBack())

 

Ok for example I want to get the ammount of losses from this database and assign the number 0 to a private integer "losses" in my code. I'm a little confused how to do this and my best guess would be the above code but I highly doubt that would work. I want to be able to get the value of losses/wins/highscore as well as get the document object id of each,   

asked Mar 18, 2014 in App42 Cloud API-BaaS by JoeCrill (25 points)
edited Mar 18, 2014 by JoeCrill

1 Answer

0 votes

To get your result, try something like this.

String key = "Losses";    
int value = 0;      
Query query = QueryBuilder.Build(key, value, Operator.EQUALS); 
storageService.FindDocumentsByQuery(dbName,collectionName,query, new UnityCallBack());   
 
For Update
 
Query query  = QueryBuilder.Build("Losses", 0, Operator.EQUALS);
storageService.UpdateDocumentByQuery(dbName, collectionName, query ,  "{\"Losses\":1000}", new UnityCallBack());
answered Mar 19, 2014 by sshukla480 (407 points)
But what if you don't know the value? Say you're logging in and the value of losses is different for each account
just blank the value filed like this.
Query query = QueryBuilder.Build(key, "", Operator.EQUALS);
So I tried assigning the object I.D. in the callback script and I got this error

Exception Is :: com.shephertz.app42.paas.sdk.csharp.App42NotFoundException: {"httpErrorCode":"404", "appErrorCode":"2608", "message":"Not Found", "details":"No document in the collection 'UserData' exists for given query"}

Here's how the code looks
App42API.SetLoggedInUser(PlayerPrefs.GetString("userName"));
Query loss_query = QueryBuilder.Build("Losses", "", Operator.EQUALS);
storageService.FindDocumentsByQuery("DATABASE","UserData",loss_query, new LossLoginCallBack());

And there is indeed a collection called UserData which is where the json for losses is located.
try something like this.
App42API.SetLoggedInUser(PlayerPrefs.GetString("userName"));
Query loss_query = QueryBuilder.Build("Losses", 0, Operator.GREATER_THAN);
This is returning all the Loss values in the database greater than 0, not just the one for the set user name :/ Also when I get the data it will be in the form {"Losses": "4"} how do I just get the 4 out of there?
If you want to fetch user specific doc, you must set login user in our query builder like this.
Query loss_query = QueryBuilder.Build("Losses", 0, Operator.GREATER_THAN);
        Query loggedInUser = QueryBuilder.SetLoggedInUser(PlayerPrefs.GetString("userName"));
        Query query = QueryBuilder.CompoundOperator(loss_query,Operator.AND,loggedInUser);
ahh ok that should work. so now my only problem is when I get the json doc it'll be something like {"Losses":4} how do I get the 4 value out of that so I can put it into a variable?
JObject jsonObj = JObject.Parse (json);
int jsonObjService = (JObject)jsonObj ["Losses"].AsInt
awesome, thanks!
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
...