quick JSON question

+1 vote

so I see that you use your collectionName to relate all your JSON objects to one name, if I set the collection name to the username will this keep track of JSON objects for each user? Something like this?

  1. String collectionName = user.getUserName());   
asked Mar 8, 2014 in App42 Cloud API-BaaS by JoeCrill (25 points)

2 Answers

0 votes

Yes, you can use your scenario, but If you only want to track your user documents you can simply use

App42API.setLoggedInUser(user.getUserName()); 

Before insert JSON objects. And to find your user documents like this.

                        Query query = QueryBuilder.setLoggedInUser(user.getUserName());
                        storageService.findDocumentsByQuery("<DB Name>","<Collection Name >",query);
answered Mar 9, 2014 by sshukla480 (407 points)
So what is finding the documents actually doing? Just getting them from the database? If I want to change information constantly wouldn't it be better to just query the data when I want to set it to player prefs and then update the data when I want to change something in the database?

Say a user wins a match and get's 500 dollars for winning, would this be the appropriate way to get and set the information?

storageService.findDocumentByKeyValue(dbName, userName, money, value, new App42CallBack() {  

storageService.updateDocumentByKeyValue(dbName, userName, money, 1000, newJsonDoc, new App42CallBack() {  

I'm a little confused as to how to properly get and set information from the database
As explained in my answer you have to first create a collection (Let’s say UserRewards) in which you have to save JSON which will have users winning points/money. If you setLoggedInuser before saving JSON object, this will automatically get attached with that user and owner of the JSON will be assigned to  same user.
If you want to update this JSON, you can do it either by objectId directly or can search document of given user(As explained by SSHUKLA480) in collection UserRewards and then updating his points stored in UserReward.
collection.
>If you setLoggedInuser before saving JSON object, this will automatically get attached with that user and owner of the JSON will be assigned to  same user.

Ahhh. Alright thanks.
`com.shephertz.app42.paas.sdk.csharp.App42API' does not contain a definition for `setLoggedInUser'

hm?

capital S in set fixed it :)
0 votes

In Storage Service, collection is like table in RDBMS database. Ideally collection should be an Entity/Noun of your system. For example, User can be a collection in which you can store user information like his name, address etc in JSON format.

In your case it  is better to create User/UserProfile collection and store username and his related information inside.

Once JSON is stored you can apply find/update method using stored information. See this for complete details.

answered Mar 9, 2014 by ajay123 (899 points)
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
...