Android
Data objects
Query Cookbook
23 min
parse query cookbook in android introduction we’ve already seen how a parsequery parsequery with get get can retrieve a single parsequery parsequery from back4app there are many other ways to retrieve data with parsequery parsequery you can retrieve many objects at once, use conditions on the objects you wish to retrieve, and more in this guide, you will ding deep into the parsequery parsequery class and see all the methods you can use to build your queries you will use a simple database class with some mocked data to perform the queries using the javascript console on back4app you can use javascript console on back4app to create mocked data easily, or you can create your data with your own android app by following this guide this tutorial uses an app created in android studio 4 1 1 with buildtoolsversion=30 0 2 buildtoolsversion=30 0 2 , compile sdk version = 30 0 2 compile sdk version = 30 0 2 and targetsdkversion=30 targetsdkversion=30 at any time, you can access the complete android project built with this tutorial at our github repositories kotlin example repository java example repository prerequisites to complete this tutorial, we need android studio an app created on back4app note follow the new parse app tutorial to learn how to create a parse app on back4app an android app connected to back4app note follow the install parse sdk tutoria l to create an android studio project connected to back4app a device (or virtual device ) running android 4 1 (jelly bean) or newer goal explore the parsequery parsequery class different methods and learn query types you can create on android the parsequery class any query operation on parse uses the parsequery parsequery object type, which will help you retrieve specific data from your back4app throughout your app to create a new parsequery parsequery , you need to pass as a parameter the desired parsequery parsequery subclass, which is the one that will contain your query results it is crucial to know that a parsequery parsequery will only resolve after calling a retrieve method (like parsequery find parsequery find or parsequery get parsequery get ), so a query can be set up and several modifiers can be chained before actually being called you can read more about the parsequery parsequery class here at the official documentation https //parseplatform org/parse sdk android/api/ using the js console on back4app inside your back4app application’s dashboard, you will find a very useful api console in which you can run javascript code directly in this guide you will use to store and query data objects from back4app on your app main dashboard go to core >api console >js console core >api console >js console save your data objects to run the queries on this guide you’ll need first to populate your app with some data let’s create a sample class called profile profile , which mocks a social media profile class using famous people names and the following fields string type date type number (integer) type array (string array) type array (number array) type geopoint type nullable pointer type here is the parse object parse object classes creation code, so go ahead and run it in your api console 1 // add profile objects and create table 2 // adam sandler 3 let profile = new parse object('profile'); 4 profile set('name', 'adam sandler'); 5 profile set('birthday', new date('09/09/1966')); 6 profile set('friendcount', 2); 7 profile set('favoritefoods', \['lobster', 'bread']); 8 profile set('luckynumbers', \[2, 7]); 9 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 10 await profile save(); 11 12 // britney spears 13 profile = new parse object('profile'); 14 profile set('name', 'britney spears'); 15 profile set('birthday', new date('12/02/1981')); 16 profile set('friendcount', 52); 17 profile set('favoritefoods', \['cake', 'bread']); 18 profile set('luckynumbers', \[22, 7]); 19 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 20 await profile save(); 21 22 // carson kressley 23 profile = new parse object('profile'); 24 profile set('name', 'carson kressley'); 25 profile set('birthday', new date('11/11/1969')); 26 profile set('friendcount', 12); 27 profile set('favoritefoods', \['fish', 'cookies']); 28 profile set('luckynumbers', \[8, 2]); 29 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 30 await profile save(); 31 32 // dan aykroyd 33 // creates related object membership for this user only 34 let membership = new parse object('membership'); 35 membership set('name', 'premium'); 36 membership set('expirationdate', new date('10/10/2030')) 37 await membership save(); 38 profile = new parse object('profile'); 39 profile set('name', 'dan aykroyd'); 40 profile set('birthday', new date('07/01/1952')); 41 profile set('friendcount', 66); 42 profile set('favoritefoods', \['jam', 'peanut butter']); 43 profile set('luckynumbers', \[22, 77]); 44 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 45 profile set('premiummembership', membership); 46 await profile save(); 47 48 // eddie murphy 49 profile = new parse object('profile'); 50 profile set('name', 'eddie murphy'); 51 profile set('birthday', new date('04/03/1961')); 52 profile set('friendcount', 49); 53 profile set('favoritefoods', \['lettuce', 'pepper']); 54 profile set('luckynumbers', \[6, 5]); 55 profile set('lastloginlocation', new parse geopoint( 27 104919974838154, 52 61428045237739)); 56 await profile save(); 57 58 // fergie 59 profile = new parse object('profile'); 60 profile set('name', 'fergie'); 61 profile set('birthday', new date('03/27/1975')); 62 profile set('friendcount', 55); 63 profile set('favoritefoods', \['lobster', 'shrimp']); 64 profile set('luckynumbers', \[13, 7]); 65 profile set('lastloginlocation', new parse geopoint( 27 104919974838154, 52 61428045237739)); 66 await profile save(); 67 68 console log('success!'); after running this code, you should now have a profile profile class in your database with six objects created your new class should look like this let’s now take a look at examples from every parsequery parsequery method, along with brief explanations on what they do please note that some methods in this list can take options options as an additional argument, but in most cases, it is only related to masterkey masterkey usage and not relevant to this guide content, so this possibility will be omitted whenever not relevant query retrievers these methods are responsible for running the query and retrieving its results, being always present in your query implementation this is the java methods cancel //cancels the current network request 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query findinbackground(); 3 query cancel(); count //retrieves the count of parseobject results that meet the query criteria 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 try { 3 int querycount = query count(); 4 log d(tag, "count " + querycount); 5 } catch (com parse parseexception parseexception) { 6 parseexception printstacktrace(); 7 } find //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works synchronously 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 try { 4 list\<parseobject> list = query find(); 5 log d(tag, "list " + list); 6 } catch (com parse parseexception e) { 7 e printstacktrace(); 8 } findinbackground //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works asynchronously 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parseerror ", e); 8 } 9 }); first //retrieves the first parseobject instance that meets the query criteria 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 try { 3 parseobject firstitem = query getfirst(); 4 log d(tag, "first item " + firstitem); 5 } catch (parseexception e) { 6 e printstacktrace(); 7 } get //this quick method is used to retrieve a single parseobject instance when you know its objectid 1 //we can call a parse object with an object id with the get() function 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 try { 4 parseobject object = query get("c6endlnfdq"); 5 log d(tag, "object " + object); 6 } catch (parseexception e) { 7 e printstacktrace(); 8 } this is the kotlin methods cancel //cancels the current network request 1 val query = parsequery\<parseobject>("profile") 2 query findinbackground() 3 query cancel() count //retrieves the count of parseobject results that meet the query criteria 1 val query = parsequery\<parseobject>("profile") 2 try { 3 val querycount = query count() 4 log d(companion tag, "count $querycount") 5 } catch (parseexception parseexception) { 6 parseexception printstacktrace() 7 } find //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works synchronously 2 val query = parsequery\<parseobject>("profile") 3 try { 4 val list = query find() 5 log d(companion tag, "list $list") 6 } catch (e parseexception) { 7 e printstacktrace() 8 } findinbackground //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works asynchronously 2 val query = parsequery\<parseobject>("profile") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parseerror ", e) 8 } 9 } first //retrieves the first parseobject instance that meets the query criteria 1 val query = parsequery\<parseobject>("profile") 2 try { 3 val firstitem = query first 4 log d(companion tag, "first item $firstitem") 5 } catch (e parseexception) { 6 e printstacktrace() 7 } get //this quick method is used to retrieve a single parseobject instance when you know its objectid 1 //we can call a parse object with an object id with the get() function 2 val query = parsequery\<parseobject>("profile") 3 try { 4 val `object` = query\["c6endlnfdq"] 5 log d(companion tag, "object $`object`") 6 } catch (e parseexception) { 7 e printstacktrace() 8 } query conditioners these methods give you the possibility of applying conditional constraints to your query, which are arguably the most important operations in querying remember that these operations can all be chained before the results are retrieved, so many combinations can be achieved to solve your querying needs these are java methods containedin //filters objects in which a key value is contained in the provided array of values 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainedin("luckynumbers", list of(2, 7)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); contains //filters objects in which a string key value contains the provided text value be aware that this condition is case sensitive 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontains("name", "da"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); cointansall //filters objects in which an array type key value must contain every value provided 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainsall("luckynumbers", list of(2, 7)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); containsallstartingwith //filters objects in which an array type key value must contain every string value provided 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainsallstartswith("favoritefoods", list of("shrimp", "lobster")); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); doesnotexist //filters objects in which a key value is not set 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wheredoesnotexist("premiummembership"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); these are kotlin methods containedin //filters objects in which a key value is contained in the provided array of values 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainedin("luckynumbers", java util list of(2, 7)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } contains //filters objects in which a string key value contains the provided text value be aware that this condition is case sensitive 1 val query = parsequery\<parseobject>("profile") 2 query wherecontains("name", "da") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } cointansall //filters objects in which an array type key value must contain every value provided 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainsall("luckynumbers", java util list of(2, 7)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } containsallstartingwith //filters objects in which an array type key value must contain every string value provided 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainsallstartswith("favoritefoods", java util list of("shrimp", "lobster")) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } doesnotexist //filters objects in which a key value is not set 1 val query = parsequery\<parseobject>("profile") 2 query wheredoesnotexist("premiummembership") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } these are java methods canceldoesnotmatchkeyinquery //requires that a key’s value does not match a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("profile"); 3 innerquery wherelessthan("friendcount", 50); 4 query wheredoesnotmatchkeyinquery("friendcount", "friendcount", innerquery); 5 query wheregreaterthan("friendcount", 10); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); doesnotmatchquery //requires that an object contained in the given key does not match another query useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("membership"); 3 innerquery wheregreaterthan("expirationdate", new date()); 4 query whereexists("premiummembership"); 5 query wheredoesnotmatchquery("premiummembership", innerquery); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); endswith //filters objects in which a string key’s value ends with the provided text value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereendswith("name", "ie"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); equalto //filters objects in which a specific key’s value is equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereequalto("friendcount", 2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); exists //filters objects in which a key value is set 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereexists("premiummembership"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); fulltext //filters objects in which a string key’s value wrap matches the provided text value in it it can have many customizable options to improve its results, like language specification and score order 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherefulltext("name", "spears"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); greaterthan //filters objects in which a specific key’s value is greater than the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 calendar calendar = calendar getinstance(); 3 calendar set(1980, 8, 19, 59, 59, 59); 4 date date = calendar gettime(); 5 query wheregreaterthan("birthday", date); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); greaterthanorequalto //filters objects in which a specific key’s value is greater than or equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wheregreaterthanorequalto("friendcount", 49); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); these are kotlin methods canceldoesnotmatchkeyinquery //requires that a key’s value does not match a value in an object returned by a different parsequery useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("profile") 3 innerquery wherelessthan("friendcount", 50) 4 query wheredoesnotmatchkeyinquery("friendcount", "friendcount", innerquery) 5 query wheregreaterthan("friendcount", 10) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } doesnotmatchquery //requires that an object contained in the given key does not match another query useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("membership") 3 innerquery wheregreaterthan("expirationdate", date()) 4 query whereexists("premiummembership") 5 query wheredoesnotmatchquery("premiummembership", innerquery) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } endswith //filters objects in which a string key’s value ends with the provided text value 1 val query = parsequery\<parseobject>("profile") 2 query whereendswith("name", "ie") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } equalto //filters objects in which a specific key’s value is equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query whereequalto("friendcount", 2) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } exists //filters objects in which a key value is set 1 val query = parsequery\<parseobject>("profile") 2 query whereexists("premiummembership") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } fulltext //filters objects in which a string key’s value wrap matches the provided text value in it it can have many customizable options to improve its results, like language specification and score order 1 val query = parsequery\<parseobject>("profile") 2 query wherefulltext("name", "spears") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } greaterthan //filters objects in which a specific key’s value is greater than the provided value 1 val query = parsequery\<parseobject>("profile") 2 val calendar = calendar getinstance() 3 calendar\[1980, 8, 19, 59, 59] = 59 4 val date = calendar time 5 query wheregreaterthan("birthday", date) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } greaterthanorequalto //filters objects in which a specific key’s value is greater than or equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wheregreaterthanorequalto("friendcount", 49) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } these are java methods lessthan //filters objects in which a specific key’s value is lesser than the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 calendar calendar = calendar getinstance(); 3 calendar set(1980, 8, 19, 59, 59, 59); 4 date date = calendar gettime(); 5 query wherelessthan("birthday", date); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); lessthanorequalto //filters objects in which a specific key’s value is lesser than or equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherelessthanorequalto("friendcount", 49); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); matches //filters objects in which a string type key value must match the provided regular expression and its modifiers 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherematches("name", "da", "i"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); matcheskeyinquery //requires that a key’s value matches a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("profile"); 3 innerquery wherelessthan("friendcount", 50); 4 query wherematcheskeyinquery("friendcount", "friendcount", innerquery); 5 query wheregreaterthan("friendcount", 10); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); matchesquery //requires that an object contained in the given key matches another query useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("membership"); 3 innerquery wheregreaterthan("expirationdate", new date()); 4 query whereexists("premiummembership"); 5 query wherematchesquery("premiummembership", innerquery); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); notequalto //filters objects in which a specific key’s value is not equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherenotequalto("friendcount", 2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); startswith //filters objects in which a string key’s value starts with the provided text value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherestartswith("name", "brit"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); these are kotlin methods lessthan //filters objects in which a specific key’s value is lesser than the provided value 1 val query = parsequery\<parseobject>("profile") 2 val calendar = calendar getinstance() 3 calendar\[1980, 8, 19, 59, 59] = 59 4 val date = calendar time 5 query wherelessthan("birthday", date) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } lessthanorequalto //filters objects in which a specific key’s value is lesser than or equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wherelessthanorequalto("friendcount", 49) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } matches //filters objects in which a string type key value must match the provided regular expression and its modifiers 1 val query = parsequery\<parseobject>("profile") 2 query wherematches("name", "da", "i") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } matcheskeyinquery //requires that a key’s value matches a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("profile") 3 innerquery wherelessthan("friendcount", 50) 4 query wherematcheskeyinquery("friendcount", "friendcount", innerquery) 5 query wheregreaterthan("friendcount", 10) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } matchesquery //requires that an object contained in the given key matches another query useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("membership") 3 innerquery wheregreaterthan("expirationdate", date()) 4 query whereexists("premiummembership") 5 query wherematchesquery("premiummembership", innerquery) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } notequalto //filters objects in which a specific key’s value is not equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wherenotequalto("friendcount", 2) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } startswith //filters objects in which a string key’s value starts with the provided text value 1 val query = parsequery\<parseobject>("profile") 2 query wherestartswith("name", "brit") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } query ordering essential in most queries, ordering can be easily achieved in parse and even chained between two or more ordering constraints these are java methods addascending //sort the results in ascending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query addascendingorder("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); adddescending //sort the results in descending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query adddescendingorder("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); ascending //sort the results in ascending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query orderbyascending("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); descending //sort the results in descending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query orderbydescending("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); these are kotlin methods addascending //sort the results in ascending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query addascendingorder("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } adddescending //sort the results in descending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query adddescendingorder("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } ascending //sort the results in ascending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query orderbyascending("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } descending //sort the results in descending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query orderbydescending("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } field selecting these methods affect which field values can be in your query results these are java methods include //return all fields in the returned objects except the ones specified 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereexists("premiummembership"); 3 query include("premiummembership"); 4 query findinbackground((objects, e) > { 5 if (e == null) { 6 log d(tag, "objects " + objects); 7 log d(tag, "object premium membership " + objects get(0) get("premiummembership")); 8 } else { 9 log e(tag, "parse error ", e); 10 } 11 12 }); select //return only the specified fields in the returned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query selectkeys(list of("name")); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 log d(tag, "object name " + objects get(0) get("name")); 7 } else { 8 log e(tag, "parse error ", e); 9 } 10 11 }); these are kotlin methods include //return all fields in the returned objects except the ones specified 1 val query = parsequery\<parseobject>("profile") 2 query whereexists("premiummembership") 3 query include("premiummembership") 4 query findinbackground { objects list\<parseobject>, e parseexception? > 5 if (e == null) { 6 log d(companion tag, "objects $objects") 7 log d( 8 companion tag, 9 "object premium membership " + objects\[0]\["premiummembership"] 10 ) 11 } else { 12 log e(companion tag, "parse error ", e) 13 } 14 } select //return only the specified fields in the returned objects 1 val query = parsequery\<parseobject>("profile") 2 query selectkeys(java util list of("name")) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 log d(companion tag, "object name " + objects\[0]\["name"]) 7 } else { 8 log e(companion tag, "parse error ", e) 9 } 10 } geopoint querying these are methods specific to geopoint querying these are java methods near //order objects by how near the key value is from the given geopoint 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherenear("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); polygoncontains //find objects whose key value contains the specified geopoint 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherepolygoncontains("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withingeobox //find objects whose key value is contained within the specified bounding box, composed by two geopoint values that set the lower left and upper right corner values 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithingeobox("lastloginlocation", new parsegeopoint(37 48412167489413, 122 11268034622319), new parsegeopoint(37 28412167489413, 121 91268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinkilometers //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinkilometers("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinmiles //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinmiles("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinpolygon //find objects whose key value is contained within the specified polygon, composed of an array of geopoints (at least three) if the polygon path is open, it will be closed automatically by parse connecting the last and first points 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinpolygon("lastloginlocation", list of(new parsegeopoint(37 48412167489413, 122 11268034622319), 3 new parsegeopoint(37 48412167489413, 121 91268034622319), 4 new parsegeopoint(37 28412167489413, 121 91268034622319), 5 new parsegeopoint(37 28412167489413, 122 01268034622319))); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 13 }); withinradians //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinradians("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); these are kotlin methods near //order objects by how near the key value is from the given geopoint 1 val query = parsequery\<parseobject>("profile") 2 query wherenear("lastloginlocation", parsegeopoint(37 38412167489413, 122 01268034622319)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } polygoncontains //find objects whose key value contains the specified geopoint 1 val query = parsequery\<parseobject>("profile") 2 query wherepolygoncontains( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319) 5 ) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } withingeobox //find objects whose key value is contained within the specified bounding box, composed by two geopoint values that set the lower left and upper right corner values 1 val query = parsequery\<parseobject>("profile") 2 query wherewithingeobox( 3 "lastloginlocation", 4 parsegeopoint(37 48412167489413, 122 11268034622319), 5 parsegeopoint(37 28412167489413, 121 91268034622319) 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinkilometers //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinkilometers( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinmiles //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinmiles( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinpolygon //find objects whose key value is contained within the specified polygon, composed of an array of geopoints (at least three) if the polygon path is open, it will be closed automatically by parse connecting the last and first points 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinpolygon( 3 "lastloginlocation", java util list of( 4 parsegeopoint(37 48412167489413, 122 11268034622319), 5 parsegeopoint(37 48412167489413, 121 91268034622319), 6 parsegeopoint(37 28412167489413, 121 91268034622319), 7 parsegeopoint(37 28412167489413, 122 01268034622319) 8 ) 9 ) 10 query findinbackground { objects list\<parseobject>, e parseexception? > 11 if (e == null) { 12 log d(companion tag, "objects $objects") 13 } else { 14 log e(companion tag, "parse error ", e) 15 } 16 } withinradians //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinradians( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } pagination these methods are related to pagination utilities, useful for queries that will retrieve a large number of results these are java methods limit //sets the maximum value of returned results, the default value is 100 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query setlimit(2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); skip //skips the first n results in the query, essential for pagination 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query setskip(2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); these are kotlin methods limit //sets the maximum value of returned results, the default value is 100 1 val query = parsequery\<parseobject>("profile") 2 query limit = 2 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } skip //skips the first n results in the query, essential for pagination 1 val query = parsequery\<parseobject>("profile") 2 query skip = 2 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } local datastore these methods enable selecting the source of the queries and using a local datastore these are java methods fromlocaldatastore //changes the source of this query to all pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 //if you want use localdatastore you should enable local data store in the app java or app kt file 3 query fromlocaldatastore(); 4 query findinbackground((objects, e) > { 5 if (e == null) { 6 log d(tag, "objects " + objects); 7 } else { 8 log e(tag, "parse error ", e); 9 } 10 11 }); fromnetwork //changes the source of this query to your online server 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query fromnetwork(); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); frompin //changes the source of this query to the default group of pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query frompin(); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); frompinwithname //changes the source of this query to a specific group of pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query frompin("pinnedobjects"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); these are kotlin methods fromlocaldatastore //changes the source of this query to all pinned objects 1 val query = parsequery\<parseobject>("profile") 2 //if you want use localdatastore you should enable local data store in the app java or app kt file 3 query fromlocaldatastore() 4 query findinbackground { objects list\<parseobject>, e parseexception? > 5 if (e == null) { 6 log d(companion tag, "objects $objects") 7 } else { 8 log e(companion tag, "parse error ", e) 9 } 10 } fromnetwork //changes the source of this query to your online server 1 val query = parsequery\<parseobject>("profile") 2 query fromnetwork() 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } frompin //changes the source of this query to the default group of pinned objects 1 val query = parsequery\<parseobject>("profile") 2 query frompin() 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } frompinwithname //changes the source of this query to a specific group of pinned objects 1 val query = parsequery\<parseobject>("profile") 2 query frompin("pinnedobjects") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } conclusion at the end of this guide, you learned how to use different query types in android