Once your app data is stored on the App42 cloud in JSON objects also referred to as JSON documents, you can query your data using finder methods available in the Storage API. There are several ways of fetching stored objects, for example using objectId or using key value reference. If you want to fetch objects based on multiple conditions (like where clause in SQL), you can use the QueryBuilder interface to write those conditions and fetching target objects.
As explained earlier, on saving any JSON object, you will get an object id( or docId) that can be used to uniquely reference stored object.
String dbName = "test"; String collectionName = "foo"; String objectId = "4faa3f1ac68df147a51f8bd7"; storageService.findDocumentById(dbName,collectionName,objectId, new App42CallBack() { public void onSuccess(Object response) { Storage storage = (Storage )response; //This will return JSONObject list, however since Object Id is unique, list will only have one object 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()); } });NSString *dbName = @"test"; NSString *collectionName = @"foo"; NSString *objectId = @"4faa3f1ac68df147a51f8bd7"; Storage *storage = [storageService findDocumentById:dbName collectionName:collectionName objectId:objectId]; //This will return JSONObject list, however since Object Id is unique, list will only have one object NSMutableArray *jsonDocArray = storage.jsonDocArray; for(JSONDocument *jsonDoc in jsonDocList) { NSLog(@"objectId is = %@ " , jsonDoc.docId); NSLog(@"JsonDoc is = %@" , jsonDoc.jsonDoc); }String dbName = "test"; String collectionName = "foo"; String objectId = "50471017c68d8e2fae756545"; storageService.FindDocumentById(dbName,collectionName,objectId, this); void App42Callback.OnSuccess(Object response) { Storage storage = (Storage) response; //This will return JSONObject list, however since Object Id is unique, list will only have one object IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList(); for(int i=0;i <JsonDocList.Count;i++) { Console.WriteLine("docId is " + JsonDocList[i].GetDocId()); //Following snippet will return the target JSON object in String format. String fetchedJSONObject = JsonDocList[i].GetJsonDoc(); } }String dbName = "test"; String collectionName = "foo"; String objectId = "4faa3f1ac68df147a51f8bd7"; Storage storage = storageService.findDocumentById(dbName,collectionName,objectId); //This will return JSONObject list, however since Object Id is unique, list will only have one object Vector JsonDocList = storage.getJsonDocList(); for(int i=0;i < JsonDocList.size();i++) { Storage.JSONDocument jsonDoc = (Storage.JSONDocument)JsonDocList.elementAt(i); System.out.println("objectId is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }var dbName = "test", collectionName = "foo", objectId = "4faa3f1ac68df147a51f8bd7"; var result ; storageService.findDocumentById(dbName,collectionName,objectId,{ success: function(object) { var storageObj = JSON.parse(object); result = storageObj.app42.response.storage; console.log("dbName is " + result.dbName) console.log("collectionName is " + result.collectionName) }, error: function(error) { } });String dbName = "test"; String collectionName = "foo"; String objectId = "4faa3f1ac68df147a51f8bd7"; Storage storage = storageService.findDocumentById(dbName,collectionName,objectId); //This will return JSONObject list, however since Object Id is unique, list will only have one object ArrayList<Storage.JSONDocument>jsonDocList = storage.getJsonDocList(); for(Storage.JSONDocument jsonDoc : jsonDocList) { System.out.println("objectId is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }String dbName = "test"; String collectionName = "foo"; String objectId = "4faa3f1ac68df147a51f8bd7"; storageService.FindDocumentById(dbName,collectionName,objectId, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { App42Log.Console("objectId is " + jsonDocList[i].GetDocId()); String fetchedJSONObject = jsonDocList[i].GetJsonDoc(); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String dbName = "test"; String collectionName = "foo"; String objectId = "4faa3f1ac68df147a51f8bd7"; Storage storage = storageService.FindDocumentById(dbName,collectionName,objectId); //This will return JSONObject list, however since Object Id is unique, list will only have one object IList<Storage.JSONDocument>jsonDocList = storage.GetJsonDocList(); for(int i = 0; i < jsonDocList.Count; i++) { Console.WriteLine("objectId is " + jsonDocList[0].GetDocId()); //Following snippet will return the target JSON object in String format String fetchedJSONObject = jsonDocList[0].GetJsonDoc(); }$dbName = "test"; $collectionName = "foo"; $objectId = "4faa3f1ac68df147a51f8bd7"; $storage = $storageService->findDocumentById($dbName, $collectionName, $objectId); //This will return JSONObject list, however since Object Id is unique, list will only have one object $jsonDocList = $storage->getJsonDocList(); foreach( $jsonDocList as $jsonDoc ) { print_r("objectId is" . $jsonDoc->getDocId()); //Following snippet will return the target JSON object in String format $fetchedJSONObject = $jsonDoc->getJsonDoc(); }dbName = "test"; collectionName = "foo"; objectId = "4faa3f1ac68df147a51f8bd7"; storage = storageService.find_document_by_id(dbName,collectionName,objectId); /* returns the Storage object. */ //This will return JSONObject list, however since Object Id is unique, list will only have one object jsonDocList = Array.new(); jsonDocList = storage.jsonDocList(); for jsonDoc in jsonDocList do puts "objectId is #{jsonDoc.docId}"; //Following snippet will return the target JSON object in String format puts "jsonDoc is #{jsonDoc.jsonDoc}"; endvar dbName:String = "dbName"; var collectionName:String = "collectionName"; var docId:String = "docId"; storageService.findDocumentById(dbName,collectionName,docId, new callback()); public class callback implements App42CallBack { public function onException(excption:App42Exception):void { trace("Exception Message"); } public function onSuccess(response:Object):void { var storage:Storage = Storage(response); trace("response is : " + storage); } }N/A
If you want to fetch an object by passing a single key its associated value for example finding objects where employeeName equals to Nick -
String dbName = "test"; String collectionName = "foo"; String key = "employeeName"; String value = "Nick"; storageService.findDocumentByKeyValue(dbName,collectionName,key,value, 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()); } });NSString *dbName = @"test"; NSString *collectionName = @"foo"; NSString *key = @"employeeName"; NSString *value = @"Nick"; Storage *storage = [storageService findDocumentByKeyValue:dbName collectionName:collectionName key:key value:value]; //This will return JSONObject list, there might be single or multiple objects if more than one object found NSMutableArray *jsonDocArray = storage.jsonDocArray; for(JSONDocument *jsonDoc in jsonDocList) { NSLog(@"docId is = %@ " , jsonDoc.docId); NSLog(@"JsonDoc is = %@" , jsonDoc.jsonDoc); }String dbName = "test"; String collectionName = "foo"; String key = "employeeName"; String value = "Nick"; storageService.FindDocumentByKeyValue(dbName,collectionName,key,value,requestCallback); /* requestCallback points instance of App42Callback which overrides OnSuccess and OnException method */ void App42Callback.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 IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList(); for(int i=0;i <JsonDocList.Count;i++) { Console.WriteLine("docId is " + JsonDocList[i].GetDocId()); //Following snippet will return the target JSON object in String format. String fetchedJSONObject = JsonDocList[i].GetJsonDoc(); } }String dbName = "test"; String collectionName = "foo"; String key = "foo"; String value = "30July"; Storage storage = storageService.findDocumentByKeyValue(dbName,collectionName,key,value); //This will return JSONObject list, however since Object Id is unique, list will only have one object Vector JsonDocList = storage.getJsonDocList(); for(int i=0;i < JsonDocList.size();i++) { Storage.JSONDocument jsonDoc = (Storage.JSONDocument)JsonDocList.elementAt(i); System.out.println("objectId is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }var dbName = "test", collectionName = "foo", key = "foo", value = "30July"; var result ; storageService.findDocumentByKeyValue(dbName,collectionName,key,value,{ success: function(object) { var storageObj = JSON.parse(object); result = storageObj.app42.response.storage; console.log("dbName is " + result.dbName) console.log("collectionName is " + result.collectionName) }, error: function(error) { } });String dbName = "test"; String collectionName = "foo"; String key = "employeeName"; String value = "Nick"; Storage storage = storageService.findDocumentByKeyValue(dbName,collectionName,key,value); //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(Storage.JSONDocument jsonDoc : jsonDocList) { System.out.println("Object Id is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }String dbName = "test"; String collectionName = "foo"; String key = "employeeName"; String value = "Nick"; storageService.FindDocumentByKeyValue(dbName,collectionName,key,value, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { App42Log.Console("objectId is " + jsonDocList[i].GetDocId()); String fetchedJSONObject = jsonDocList[i].GetJsonDoc(); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String dbName = "test"; String collectionName = "foo"; String key = "employeeName"; String value = "Nick"; Storage storage = storageService.FindDocumentByKeyValue(dbName,collectionName,key,value); //This will return JSONObject list, there might be single or multiple objects if more than one object found IList<Storage.JSONDocument>jsonDocList = storage.GetJsonDocList(); for(int i = 0; i < jsonDocList.Count; i++) { Console.WriteLine("objectId is " + jsonDocList[0].GetDocId()); //Following snippet will return the target JSON object in String format String fetchedJSONObject = jsonDocList[0].GetJsonDoc(); }$dbName = "test"; $collectionName = "foo"; $key = "employeeName"; $value = "Nick"; $storage = $storageService->findDocumentByKeyValue($dbName, $collectionName, $key, $value); //This will return JSONObject list, there might be single or multiple objects if more than one object found $jsonDocList = $storage->getJsonDocList(); foreach( $jsonDocList as $jsonDoc ) { print_r("objectId is" . $jsonDoc->getDocId()); //Following snippet will return the target JSON object in String format $fetchedJSONObject = $jsonDoc->getJsonDoc(); }dbName = "test"; collectionName = "foo"; key = "employeeName"; value = "Nick"; storage = storageService.find_document_by_key_value(dbName,collectionName,key,value); //This will return JSONObject list, there might be single or multiple objects if more than one object found jsonDocList = Array.new(); jsonDocList = storage.jsonDocList(); for jsonDoc in jsonDocList do puts "objectId is #{jsonDoc.docId}"; //Following snippet will return the target JSON object in String format puts "jsonDoc is #{jsonDoc.jsonDoc}"; endvar dbName:String = "test"; var collectionName:String = "foo"; var key:String = "employeeName"; var value:String = "Nick"; storageService.findDocumentByKeyValue(dbName,collectionName,key,value,new callback()); public class callback implements App42CallBack { public function onException(excption:App42Exception):void { trace("Exception Message"); } public function onSuccess(response:Object):void { var storage:Storage = Storage(response); trace("response is : " + storage); } }N/A
If you want to fetch objects by passing multiple conditions, for example finding objects where employeeName equals to Nick AND age GREATER_THAN 30 -
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 the target JSON object JSONObject jsonObject = new JSONObject(jsonDocList.get(i).getJsonDoc()); } } public void onException(Exception ex) { System.out.println("Exception Message"+ex.getMessage()); } });NSString *dbName = @"dbName"; NSString *collectionName = @"collectionName"; NSString *key = @"employeeName"; NSString *value = @"Nick"; NSString *key1 = @"age"; NSNumber *value1= [NSNumber numberWithInt:30]; Query *q1 = [QueryBuilder buildQueryWithKey:key value:value operator:APP42_OP_EQUALS]; // Build query q1 for key equal to key Query *q2 = [QueryBuilder buildQueryWithKey:key1 value:value1 operator:APP42_OP_GREATER_THAN]; // Build query q2 for value1 greater than 30 Query *q3 = [QueryBuilder combineQuery:q1 withQuery:q2 usingOperator:APP42_OP_AND]; // Apply AND between q1 and q2 Storage *storage = [storageService findDocumentsByQuery:q3 dbName:dbName collectionName:collectionName]; //This will return JSONObject list, there might be single or multiple objects if more than one object found NSMutableArray *jsonDocArray = storage.jsonDocArray; for(JSONDocument *jsonDoc in jsonDocList) { NSLog(@"docId is = %@ " , jsonDoc.docId); NSLog(@"JsonDoc is = %@" , jsonDoc.jsonDoc); }String dbName = "test"; String collectionName = "foo"; // 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); // Pass aggregated query q3 to finder method below. Similarly you can aggregate more conditions in querying object. storageService.FindDocumentsByQuery(dbName,collectionName,q3, requestCallback ); /* requestCallback points instance of App42Callback which overrides OnSuccess and OnException method */ void App42Callback.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 IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList(); for(int i=0;i <JsonDocList.Count;i++) { Console.WriteLine("docId is " + JsonDocList[i].GetDocId()); //Following snippet will return the target JSON object in String format. String fetchedJSONObject = JsonDocList[i].GetJsonDoc(); } } }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); Storage storage = storageService.findDocumentsByQuery(dbName,collectionName,q3); //This will return JSONObject list, however since Object Id is unique, list will only have one object Vector JsonDocList = storage.getJsonDocList(); for(int i=0;i < JsonDocList.size();i++) { Storage.JSONDocument jsonDoc = (Storage.JSONDocument)JsonDocList.elementAt(i); System.out.println("objectId is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }var dbName = "test", collectionName = "foo", result ; var queryBuilder = new QueryBuilder(); // Build query q1 for employeeName equal to Nick var q1= queryBuilder.build("employeeName", "Nick", Operator.EQUALS); // Build query q2 for age greater than 30 var q2 = queryBuilder.build("age", 30, Operator.GREATER_THAN); // Apply AND between q1 and q2 var q3 = queryBuilder.compoundOperator(q1,Operator.AND, q2); storage.findDocumentsByQuery(dbName, collectionName, q3,{ success: function(object) { //This will return JSONObject list, there might be single or multiple objects if more than one object found var storageObj = JSON.parse(object); result = storageObj.app42.response.storage; console.log("dbName is " + result.dbName) console.log("collectionName is " + result.collectionName) }, error: function(error) { } });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); Storage storage = storageService.findDocumentsByQuery(dbName,collectionName,q3); //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(Storage.JSONDocument jsonDoc : jsonDocList) { System.out.println("Object Id is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }String dbName = "test"; String collectionName = "foo"; // 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); // Pass aggregated query q3 to the finder method below. Similarly you can aggregate more conditions while querying the object. storageService.FindDocumentsByQuery(dbName,collectionName,q3, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { App42Log.Console("objectId is " + jsonDocList[i].GetDocId()); String fetchedJSONObject = jsonDocList[i].GetJsonDoc(); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String dbName = "test"; String collectionName = "foo"; // 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); // Pass aggregated query q3 to finder method below. Similarly you can aggregate more conditions while querying the object. Storage storage = storageService.FindDocumentsByQuery(dbName,collectionName,q3); //This will return JSONObject list, there might be single or multiple objects if more than one object found IList<Storage.JSONDocument>jsonDocList = storage.GetJsonDocList(); for(int i = 0; i < jsonDocList.Count; i++) { Console.WriteLine("objectId is " + jsonDocList[0].GetDocId()); //Following snippet will return the target JSON object in String format String fetchedJSONObject = jsonDocList[0].GetJsonDoc(); }$dbName = "test"; $collectionName = "foo"; $query = new QueryBuilder(); // Build query q1 for name equal to Nick $q1 = $query->build("employeeName", "Nick", Operator::EQUALS); // Build query q2 for age greater than 30 $q2 = $query->build("age", 30, Operator::GREATER_THAN); // Apply AND between q1 and q2 $q3 = $query->compoundOperator($q1, Operator::ANDop, $q2); // Pass aggregated query q3 to finder method below. Similarly you can aggregate more conditions in querying object. $storage = $storageService->findDocumentsByQuery($dbName,$collectionName,$q3); //This will return JSONObject list, there might be single or multiple objects if more than one object found $jsonDocList = $storage->getJsonDocList(); foreach( $jsonDocList as $jsonDoc ) { print_r("objectId is" . $jsonDoc->getDocId()); //Following snippet will return the target JSON object in String format $fetchedJSONObject = $jsonDoc->getJsonDoc(); }dbName = "test"; collectionName = "foo"; op = App42::Storage::QueryBuilder::Operator.new(); qb = App42::Storage::QueryBuilder.new(); // Build query q1 for name equal to Nick q1 = qb.build("employeeName", "Nick", op.enum("EQUALS")); // Build query q2 for age greater than 30 q2 = qb.build("age", 30, op.enum("GREATER_THAN")); // Apply AND between q1 and q2 q3 = qb.compoundOperator(q1, op.enum("AND"), q2); // Pass aggregated query q3 to finder method below. Similarly you can aggregate more conditions while querying the object. storage = storageService.find_documents_by_query(dbName, collectionName, q3); //This will return fetched JSONObject list, there might be single or multiple objects if more than one object found jsonDocList = Array.new(); jsonDocList = storage.jsonDocList(); for jsonDoc in jsonDocList do puts "objectId is #{jsonDoc.docId}"; //Following snippet will return the target JSON object in String format puts "jsonDoc is #{jsonDoc.jsonDoc}"; endvar dbName:String = "test"; var collectionName:String = "foo"; var q1:Query = QueryBuilder.build("employeeName", "Nick", Operator.EQUALS); var q2:Query = QueryBuilder.build("age", 30, Operator.GREATER_THAN); var q3:Query = QueryBuilder.compoundOperator(q1, Operator.AND, q2); storageService.findDocumentsByQuery(dbName, collectionName, q3,new callback()); public class callback implements App42CallBack { public function onException(excption:App42Exception):void { trace("Exception Message"); } public function onSuccess(response:Object):void { var storage:Storage = Storage(response); var jsonDoc:JSONDocument = new JSONDocument(); trace("response is : " + storage); jsonDoc = JSONDocument(storage.getJsonDocList()[0]); trace("objectId is : " + jsonDoc.getDocId()); trace("jsonDoc is : " + jsonDoc.getJsonDoc()); //This will return JSONObject list, however since Object Id is unique } }N/A
If your stored app data contains date field stored in UTC format (See How to Store Date Object ?), you can query on it using search operator to fetch stored objects.
java.util.Date dateTobeSearched= new Date(); // Date on which you want to query String utcDateFormat = com.shephertz.app42.paas.sdk.android.util.Util.getUTCFormattedTimestamp(dateTobeSearched); // building query. Query query = QueryBuilder.build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. storageService.findDocumentsByQuery(dbName, collectionName, query, 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()); } });NSString *dbName = @"dbName"; NSString *collectionName = @"collectionName"; NSDate *dateTobeSearched= [NSDate date]; // Date on which you want to query NSString *utcDateFormat = [Utils getUTCTimeFormattedStamp:dateTobeSearched]; // building query. Query *query = [QueryBuilder buildQueryWithKey:@"DOB" value:utcDateFormat andOperator:APP42_OP_EQUALS]; // find documents by query. Storage *storage = [storageObj findDocumentsByQuery:query dbName:dbName collectionName:collectionName]; NSArray *jsonDocList = [storage jsonDocArray]; for(JSONDocument *jsonDoc in jsonDocList) { NSLog(@"Object Id is %@",jsonDoc.docId); }String dbName = "queryTest"; String collectionName = "foo"; DateTime dateTobeSearched= DateTime.Now; // Date on which you want to query String utcDateFormat = com.shephertz.app42.paas.sdk.windows.util.Util.GetUTCFormattedTimestamp(dateTobeSearched); // building query. Query query = QueryBuilder.Build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. storageService.FindDocumentByQuery(dbName, collectionName, query, this); public class Callback : App42Callback { public void OnException(App42Exception exception) { Console.WriteLine("Exception Message : " + exception); } public void OnSuccess(Object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { Console.WriteLine("DocId is : " + jsonDocList[i].GetDocId()); Console.WriteLine("JSONDoc is : " + jsonDocList[i].GetJsonDoc()); } } }java.util.Date dateTobeSearched= new Date(); // Date on which you want to query String utcDateFormat = com.shephertz.app42.paas.sdk.jme.util.Util.getUTCFormattedTimestamp(dateTobeSearched); // building query. Query query = QueryBuilder.build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. Storage storage = storageService.findDocumentsByQuery(dbName, collectionName, query);var dbName = "test"; var collectionName = "foo"; var queryBuilder = new QueryBuilder(); var utcDateFormat = new Date().toJSON(); var jsonData = {} jsonData.name = "Nick" jsonData.DOB = utcDateFormat // building query. var q1 = queryBuilder.build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. storageService.findDocumentsByQuery(dbName, collectionName, q1,{ success: function(object) { console.log(object) }, error: function(error) { console.log(error) } });java.util.Date dateTobeSearched= new Date(); // Date on which you want to query String utcDateFormat = com.shephertz.app42.paas.sdk.java.util.Util.getUTCFormattedTimestamp(dateTobeSearched); // building query. Query query = QueryBuilder.build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. Storage storage = storageService.findDocumentsByQuery(dbName, collectionName, query); ArrayList<Storage.JSONDocument>jsonDocList = storage.getJsonDocList(); for(Storage.JSONDocument jsonDoc : jsonDocList) { System.out.println("Object Id is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }String dbName = "test"; String collectionName = "foo"; DateTime dateTobeSaved = DateTime.Now; // Date that you want to save String utcDateFormat = com.shephertz.app42.paas.sdk.csharp.util.Util.GetUTCFormattedTimestamp(dateTobeSaved); // building query. Query query = QueryBuilder.Build("DOB", utcDateFormat, Operator.EQUALS); storageService.FindDocumentsByQuery(dbName,collectionName, query, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { App42Log.Console("objectId is " + jsonDocList[i].GetDocId()); String fetchedJSONObject = jsonDocList[i].GetJsonDoc(); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String dbName = "test"; String collectionName = "foo"; DateTime dateTobeSaved = DateTime.Now; // Date that you want to save String utcDateFormat = com.shephertz.app42.paas.sdk.csharp.util.Util.GetUTCFormattedTimestamp(dateTobeSaved); // building query. Query query = QueryBuilder.Build("DOB", utcDateFormat, Operator.EQUALS); // find documents by query. Storage storage = storageService.FindDocumentsByQuery(dbName, collectionName, query); IList<Storage.JSONDocument>jsonDocList = storage.GetJsonDocList(); foreach(Storage.JSONDocument jsonDoc in jsonDocList) { Console.WriteLine("Object Id is " + jsonDoc.GetDocId()); //Following snippet will return the target JSON object JSONData jsonObject = (JSONData)jsonDoc.GetJsonDoc(); }TBDTBDvar dbName:String = "test"; var collectionName:String = "foo"; var dateTobeSearched:Date = new Date(); var utcDateFormat:String= com.shephertz.app42.paas.sdk.as3.util.Util.getUTCTimestampFromDate(dateTobeSearched); // building query. var query:Query = QueryBuilder.build("DOB", utcDateFormat, Operator.EQUALS); storageService.findDocumentsByQuery(dbName, collectionName, query,new callback()); public class callback implements App42CallBack { public function onException(excption:App42Exception):void { trace("Exception Message"); } public function onSuccess(response:Object):void { var storage:Storage = Storage(response); trace("dbName is : " + storage.getDbName()); trace("collectionName is : " + storage.getCollectionName()); var jsonDoc:JSONDocument = new JSONDocument(); for(var i:int = 0; i<storage.getJsonDocList().length;i++) { jsonDoc = JSONDocument(storage.getJsonDocList()[i]); trace("objectId is : " + jsonDoc.getDocId()); trace("jsonDoc is : " + jsonDoc.getJsonDoc()); } } }N/A
If your stored JSON app data contains geo tags (See How to Store JSON Object with Geo Tag ?), you can fetch it using geo query from any given location (lat and long) and range as shown below in code snippet.
BigDecimal distanceInKM = new BigDecimal(1); GeoTag gp = new GeoTag(); gp.setLat(new BigDecimal(-73.99171)); gp.setLng(new BigDecimal(40.738868)); GeoQuery query = QueryBuilder.buildGeoQuery(gp, GeoOperator.NEAR, distanceInKM); // find documents by geo query. storageService.findDocumentsByLocation(dbName, collectionName, query, 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()); } });NSString *dbName = @"dbName"; NSString *collectionName = @"collectionName"; GeoTag *geoTag = [[GeoTag alloc] initWithLatitude:20.2 andLongitude:50.5]; storageService.geoTag = [geoTag toString]; //Pass Distance in KM GeoQuery *query = [QueryBuilder buildGeoQueryWithTag:geoTag andOperator:APP42_OP_NEAR maxDistance:10]; // find documents by geo query. Storage *storage = [storageObj findDocumentsByLocation:query dbName:dbName collectionName:collectionName]; NSArray *jsonDocList = [storage jsonDocArray]; for(JSONDocument *jsonDoc in jsonDocList) { NSLog(@"Object Id is %@",jsonDoc.docId); }String dbName = "queryTest"; String collectionName = "foo"; Double distanceInKM = new Double(1.0); GeoTag gp = new GeoTag(); gp.SetLat(-73.99171); gp.SetLng(40.738868); storageService.SetGeoTag(gp); GeoQuery query = QueryBuilder.BuildGeoQuery(gp, GeoOperator.WITHIN, distanceInKM); // find documents by geo query. storageService.FindDocumentsByLocation(dbName, collectionName, query, this); public class Callback : App42Callback { public void OnException(App42Exception exception) { Console.WriteLine("Exception Message : " + exception); } public void OnSuccess(Object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { Console.WriteLine("DocId is : " + jsonDocList[i].GetDocId()); Console.WriteLine("JSONDoc is : " + jsonDocList[i].GetJsonDoc()); } } }Double distanceInKM = new Double(1); GeoTag gp = new GeoTag(); gp.setLat(new Double(-73.99171)); gp.setLng(new Double(40.738868)); GeoQuery query = QueryBuilder.buildGeoQuery(gp, GeoOperator.NEAR, distanceInKM); // find documents by geo query. Storage storage = storageService.findDocumentsByLocation(dbName, collectionName, query);var dbName = "test"; var collectionName = "foo"; var gp = new GeoTag(); gp.setLat(-73.1234) gp.setLng(-26.1234) var queryBuilder = new QueryBuilder(); //Distance in KM var q1 = queryBuilder.buildGeoQuery(gp, GeoOperator.NEAR, 100); // find documents by query. storageService.findDocumentsByLocation(dbName, collectionName, q1,{ success: function(object) { console.log(object) }, error: function(error) { console.log(error) } });BigDecimal distanceInKM = new BigDecimal(1); GeoTag gp = new GeoTag(); gp.setLat(new BigDecimal(-73.99171)); gp.setLng(new BigDecimal(40.738868)); GeoQuery query = QueryBuilder.buildGeoQuery(gp, GeoOperator.NEAR, distanceInKM); // find documents by geo query. Storage storage = storageService.findDocumentsByLocation(dbName, collectionName, query); ArrayList<Storage.JSONDocument>jsonDocList = storage.getJsonDocList(); for(Storage.JSONDocument jsonDoc : jsonDocList) { System.out.println("Object Id is " + jsonDoc.getDocId()); //Following snippet will return the target JSON object JSONObject jsonObject = new JSONObject(jsonDoc.getJsonDoc()); }String dbName = "<Your_DataBase_Name>"; String collectionName = "<Your_Collection_Name>"; GeoTag gp = new GeoTag(); gp.SetLat(-73.99171); gp.SetLng(40.738868); storageService.SetGeoTag(gp); GeoQuery query = QueryBuilder.BuildGeoQuery(gp, GeoOperator.NEAR, new BigDecimal(100)); storageService.FindDocumentsByLocation(dbName, collectionName, query, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Storage storage = (Storage) response; IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList(); for(int i=0;i <jsonDocList.Count;i++) { App42Log.Console("objectId is " + jsonDocList[i].GetDocId()); App42Log.Console("jsonDoc is " + jsonDocList[i].GetJsonDoc()); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String dbName = "test"; String collectionName = "foo"; Double distanceInKM = new Double(1.0); GeoTag gp = new GeoTag(); gp.SetLat(-73.99171); gp.SetLng(40.738868); GeoQuery query = QueryBuilder.BuildGeoQuery(gp, GeoOperator.WITHIN, distanceInKM); // find documents by geo query. Storage storage = storageService.FindDocumentsByLocation(dbName, collectionName, query); IList<Storage.JSONDocument>jsonDocList = storage.GetJsonDocList(); foreach(Storage.JSONDocument jsonDoc in jsonDocList) { Console.WriteLine("Object Id is " + jsonDoc.GetDocId()); //Following snippet will return the target JSON object JSONData jsonObject = (JSONData)jsonDoc.GetJsonDoc(); }TBDTBDTBDN/A