Find Specific Key From JSON Document

0 votes
Hi, App42 support team:
my code:
HashSet<string> selectKeys = new HashSet<string> ();  
selectKeys.Add("user1");  
selectKeys.Add("user2");  
selectKeys.Add("user3");  
GGCloudServiceAdapter.mInstance.mStorageService.SetSelectKeys (selectKeys);  
Storage storage = GGCloudServiceAdapter.mInstance.mStorageService.FindAllDocuments ( "PLAY1", "DataCollection");
IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList();
 
question1: Is this way corret? why I get 100 records every time? why the infomation I get isn't correct by the above way?
question2: Is there a way to query multiple key( eg. 10 different keys)? 
Thank you!
 
asked Aug 19, 2014 in App42 Cloud API-BaaS by riovoxtools (45 points)
edited Aug 19, 2014 by riovoxtools

1 Answer

0 votes

Hello Riovox,

Yes, this is the correct way for finding the doc based on multiple keys. Please use the findAllDocumentsByPaging method for finding all the documents by paging from App42 data base. 

Also, find the below code snippet for finding the docs using multiple keys:

 

String dbName = "test";  

String collectionName = "foo";  

String key = "employeeName";  

String value = "Nick"; 

// Build query q1 for name equal to Nick 

Query q1 = QueryBuilder.build("employeeName", "Nick", Operator.EQUALS);

// Build query q2 for age greater than 30       

Query q2 = QueryBuilder.build("age", 30, Operator.GREATER_THAN); 

// Apply AND between q1 and q2     

Query q3 = QueryBuilder.compoundOperator(q1, Operator.AND, q2);        

storageService.findDocumentsByQuery(dbName,collectionName,q3, new App42CallBack() {

public void onSuccess(Object response) 

{

            Storage  storage  = (Storage )response;

            //This will return JSONObject list, there might be single or multiple objects if more than one object found

            ArrayList<Storage.JSONDocument> jsonDocList = storage.getJsonDocList();            

            for(int i=0;i<jsonDocList.size();i++)

            {

                        System.out.println("objectId is " + jsonDocList.get(i).getDocId());  

                        System.out.println("CreatedAt is " + jsonDocList.get(i).getCreatedAt());  

                        System.out.println("UpdatedAtis " + jsonDocList.get(i).getUpdatedAt());  

                        //Following snippet will return target JSON object 

                        JSONObject jsonObject = new JSONObject(jsonDocList.get(i).getJsonDoc()); 

            } 

}

public void onException(Exception ex) 

{

            System.out.println("Exception Message"+ex.getMessage());            

}

}); 

 

Let us know if it helps.

Thanks.

 

answered Aug 19, 2014 by hs00105 (2,005 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
...