Hi Checker,
If I understood your query correctly then you are calling the below function before inserting a JSON document in Storage service:
App42.setLoggedInUser("UserName");
The benefits of using the above function are, it will map that username as an owner of that document. So at the time of fetching the document, you can create query based on owner as shown in the below code snippet:
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("_$owner.owner", "UserName", Operator.EQUALS);
storageService.findDocumentsByQuery(dbName,collectionName,q1, 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 the target JSON object
JSONObject jsonObject = new JSONObject(jsonDocList.get(i).getJsonDoc());
}
}
public void onException(Exception ex)
{
System.out.println("Exception Message"+ex.getMessage());
}
});
Could you please elaborate this more "how can i retreve the json objects with a particular value to a attribute in a collection"? Because if I understood this correctly then you want the specific key in response JSON. If yes, then please have a look at this
link for the code snippet and let me know if it helps.
Regards,
Himanshu Sharma