React Native
...
Data objects
Query Cookbook
22 min
livro de receitas de consultas parse em react native introdução já vimos como um parse query parse query com get get pode recuperar um único parse object parse object do back4app existem muitas outras maneiras de recuperar dados com parse query parse query você pode recuperar muitos objetos de uma vez, usar condições nos objetos que deseja recuperar, e mais neste guia, você irá se aprofundar na parse query parse query classe e ver todos os métodos que você pode usar para construir suas consultas você usará uma classe de banco de dados simples com alguns dados simulados para realizar as consultas usando o console javascript no back4app pré requisitos para completar este tutorial, você precisará um app criado no back4app objetivo explore a parse query parse query classe e seus diferentes métodos a classe parse query qualquer operação de consulta no parse usa o parse query parse query tipo de objeto, que ajudará você a recuperar dados específicos do seu back4app ao longo do seu aplicativo para criar um novo parse query parse query , você precisa passar como parâmetro a parse object parse object desejada, que é a que conterá os resultados da sua consulta é crucial saber que um parse query parse query só será resolvido após chamar um método de recuperação (como parse query find parse query find ou parse query get parse query get ), então uma consulta pode ser configurada e vários modificadores podem ser encadeados antes de realmente serem chamados você pode ler mais sobre a parse query parse query classe aqui na documentação oficial https //parseplatform org/parse sdk js/api/master/parse query html usando o console js no back4app dentro do painel da sua aplicação back4app, você encontrará um console de api muito útil no qual pode executar código javascript diretamente neste guia, você usará para armazenar e consultar objetos de dados do back4app no painel principal do seu aplicativo, vá para core >api console >js console core >api console >js console salve seus objetos de dados para executar as consultas neste guia, você precisará primeiro preencher seu aplicativo com alguns dados vamos criar uma classe de exemplo chamada perfil, que simula uma classe de perfil de mídia social usando nomes de pessoas famosas e os seguintes campos tipo string nome nome tipo data datadenascimento datadenascimento tipo número (inteiro) contagemdeamigos contagemdeamigos tipo array (array de strings) comidasfavoritas comidasfavoritas tipo array (array de números) númerosdasorte númerosdasorte tipo geopoint localizaçãodelogin localizaçãodelogin tipo ponteiro anulável assinaturapremium assinaturapremium , relacionado a uma assinatura assinatura classe contendo string nome nome e data datadeexpiração datadeexpiração campos aqui está o parse object parse object código de criação de classes, então vá em frente e execute o no console da sua api 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!'); após executar este código, você agora deve ter uma perfil perfil classe em seu banco de dados com seis objetos criados sua nova classe deve parecer com isso vamos agora dar uma olhada em exemplos de cada parse query parse query método, juntamente com breves explicações sobre o que eles fazem por favor, note que alguns métodos nesta lista podem aceitar opções opções como um argumento adicional, mas na maioria dos casos, isso está relacionado apenas ao uso de masterkey masterkey e não é relevante para o conteúdo deste guia, então essa possibilidade será omitida sempre que não for relevante recuperadores de consulta esses métodos são responsáveis por executar a consulta e recuperar seus resultados, estando sempre presentes na implementação da sua consulta cancel //cancels the current network request 1 let query = new parse query('profile'); 2 let queryresult = await query find(); 3 // this is hard to test in small databases, since by the time 4 // "cancel" is called, the "find" request is already resolved 5 queryresult = query cancel(); 6 console log(queryresult); count //retrieves the count of parse object results that meet the query criteria 1 let query = new parse query('profile'); 2 let queryresult = await query count(); 3 console log(queryresult); distinct //runs the query and returns a list of unique values from the results and the specified key 1 let query = new parse query('profile'); 2 let queryresult = await query distinct('favoritefoods'); 3 console log(queryresult); find //this is the basic method for retrieving your query results, always returning an array of parse object instances, being empty when none are found 1 let query = new parse query('profile'); 2 // when using find() in a query without other operations, you will 3 // get every object saved in your class 4 let queryresult = await query find(); 5 console log(queryresult); findall //retrieves a complete list of parse objects that satisfy this query 1 let query = new parse query('profile'); 2 // when using findall() in a query without other operations, you will 3 // get every object saved in your class 4 let queryresult = await query findall(); 5 console log(queryresult); first //retrieves the first parse object instance that meets the query criteria 1 let query = new parse query('profile'); 2 // pay attention to your query ordering when using first 3 let queryresult = await query first(); 4 console log(queryresult); get //this quick method is used to retrieve a single parse object instance when you know its objectid 1 let query = new parse query('profile'); 2 // since objectid is randomly set in your database, make sure to inform a 3 // valid one when testing this method 4 let queryresult = await query get('c6endlnfdq'); 5 console log(queryresult); condicionadores de consulta esses métodos oferecem a possibilidade de aplicar restrições condicionais à sua consulta, que são, sem dúvida, as operações mais importantes na consulta lembre se de que todas essas operações podem ser encadeadas antes que os resultados sejam recuperados, portanto, muitas combinações podem ser alcançadas para resolver suas necessidades de consulta addcondition // helper that is called by parse for filtering objects using conditional constants, such as “$gt”, “$eq” and so on only usable by users in very specific cases 1 let query = new parse query('profile'); 2 query addcondition('friendcount', '$gt', 25); 3 let queryresult = await query find(); 4 console log(queryresult); regexstartwith //helper used by parse that converts string for regular expression at the beginning 1 let query = new parse query('profile'); 2 let result = query regexstartwith('text'); 3 console log(result); containedby //filters objects in which a key value must be contained by the provided array of values get objects where all array elements match 1 let query = new parse query('profile'); 2 query containedby('luckynumbers', \[2, 7]); 3 let queryresult = await query find(); 4 console log(queryresult); containedin //filters objects in which a key value is contained in the provided array of values 1 let query = new parse query('profile'); 2 // containedin can be used on any data type such as numbers and strings 3 query containedin('luckynumbers', \[2, 7]); 4 let queryresult = await query find(); 5 console log(queryresult); contains //filters objects in which a string key value contains the provided text value be aware that this condition is case sensitive 1 let query = new parse query('profile'); 2 // this can be slow in large databases and are case sensitive 3 query contains('name', 'da'); 4 let queryresult = await query find(); 5 console log(queryresult); containsall //filters objects in which an array type key value must contain every value provided 1 let query = new parse query('profile'); 2 query containsall('luckynumbers', \[2, 7]); 3 let queryresult = await query find(); 4 console log(queryresult); containsallstartingwith //filters objects in which an array type key value must contain every string value provided 1 let query = new parse query('profile'); 2 // these should be string values 3 query containsallstartingwith('favoritefoods', \['shrimp', 'lobster']); 4 let queryresult = await query find(); 5 console log(queryresult); doesnotexist //filters objects in which a key value is not set 1 let query = new parse query('profile'); 2 query doesnotexist('premiummembership'); 3 let queryresult = await query find(); 4 console log(queryresult); doesnotmatchkeyinquery // requires that a key’s value does not match a value in an object returned by a different parse query useful for multi object querying 1 let query = new parse query('profile'); 2 // multiple queries can be combined using this, useful when there are more objects 3 // related, not our example case 4 query doesnotmatchkeyinquery('friendcount', 'friendcount', new parse query('profile') lessthan('friendcount', 50)); 5 query greaterthan('friendcount', 10); 6 let queryresult = await query find(); 7 console log(queryresult); doesnotmatchquery //requires that an object contained in the given key does not match another query useful for multi object querying 1 let innerquery = new parse query('membership'); 2 innerquery greaterthan('expirationdate', new date()); 3 let query = new parse query('profile'); 4 query exists('premiummembership'); 5 query doesnotmatchquery('premiummembership', innerquery); 6 let queryresult = await query find(); 7 console log(queryresult); endswith //filters objects in which a string key’s value ends with the provided text value 1 let query = new parse query('profile'); 2 // this is faster than other string searches by using backend index 3 query endswith('name', 'ie'); 4 let queryresult = await query find(); 5 console log(queryresult); equalto //filters objects in which a specific key’s value is equal to the provided value 1 let query = new parse query('profile'); 2 // equalto can be used in any data type 3 query equalto('friendcount', 2); 4 let queryresult = await query find(); 5 console log(queryresult); exists //filters objects in which a key value is set 1 let query = new parse query('profile'); 2 query exists('premiummembership'); 3 let queryresult = await query find(); 4 console log(queryresult); 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 check the parse docs to have a complete understanding of that 1 let query = new parse query('profile'); 2 // fulltext can be very powerful in text search queries, but 3 // also slow in large datasets when its options are not optimized 4 query fulltext('name', 'spears', { diacriticsensitive false, casesensitive false }); 5 // in order to sort you must use select and ascending ($score is required) 6 query ascending('$score'); 7 query select('$score'); 8 let queryresult = await query find(); 9 console log(queryresult); greaterthan //filters objects in which a specific key’s value is greater than the provided value 1 let query = new parse query('profile'); 2 // greaterthan can be used on numbers and dates 3 query greaterthan('birthday', new date('08/19/1980')); 4 let queryresult = await query find(); 5 console log(queryresult); greaterthanorequalto //filters objects in which a specific key’s value is greater than or equal to the provided value 1 let query = new parse query('profile'); 2 // greaterthanorequalto can be used on numbers and dates 3 query greaterthanorequalto('friendcount', 49); 4 let queryresult = await query find(); 5 console log(queryresult); lessthan // filters objects in which a specific key’s value is lesser than the provided value 1 let query = new parse query('profile'); 2 // lessthan can be used on numbers and dates 3 query lessthan('birthday', new date('08/19/1980')); 4 let queryresult = await query find(); 5 console log(queryresult); lessthanorequalto //filters objects in which a specific key’s value is lesser than or equal to the provided value 1 let query = new parse query('profile'); 2 // lessthanorequalto can be used on numbers and dates 3 query lessthanorequalto('friendcount', 49); 4 let queryresult = await query find(); 5 console log(queryresult); matches //filters objects in which a string type key value must match the provided regular expression and its modifiers 1 let query = new parse query('profile'); 2 // using the "i" modifier is a quick way to achieve 3 // case insensitive string querying 4 query matches('name', 'da', 'i'); 5 let queryresult = await query find(); 6 console log(queryresult); matcheskeyinquery //requires that a key’s value matches a value in an object returned by a different parse query useful for multi object querying 1 let query = new parse query('profile'); 2 // multiple queries can be combined using this, useful when there are more objects 3 // related, not our example case 4 query matcheskeyinquery('friendcount', 'friendcount', new parse query('profile') lessthan('friendcount', 50)); 5 query greaterthan('friendcount', 10); 6 let queryresult = await query find(); 7 console log(queryresult); matchesquery //requires that an object contained in the given key matches another query useful for multi object querying 1 let innerquery = new parse query('membership'); 2 innerquery greaterthan('expirationdate', new date()); 3 let query = new parse query('profile'); 4 query exists('premiummembership'); 5 query matchesquery('premiummembership', innerquery); 6 let queryresult = await query find(); 7 console log(queryresult); notequalto //filters objects in which a specific key’s value is not equal to the provided value 1 let query = new parse query('profile'); 2 // notequalto can be used in any data type 3 query notequalto("friendcount", 2); 4 let queryresult = await query find(); 5 console log(queryresult); startswith //filters objects in which a string key’s value starts with the provided text value 1 let query = new parse query('profile'); 2 // this is faster than other string searches by using backend index 3 query startswith('name', 'brit'); 4 let queryresult = await query find(); 5 console log(queryresult); ordenação de consultas essencial na maioria das consultas, a ordenação pode ser facilmente alcançada no parse e até encadeada entre duas ou mais restrições de ordenação addascending // sort the results in ascending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 let query = new parse query('profile'); 2 query addascending('friendcount'); 3 let queryresult = await query find(); 4 console log(queryresult); adddescending //sort the results in descending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 let query = new parse query('profile'); 2 query adddescending('friendcount'); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query ascending('friendcount'); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query descending('friendcount'); 3 let queryresult = await query find(); 4 console log(queryresult); sortbytextscore //sorts by text score when using parse query fulltext 1 let query = new parse query('profile'); 2 query fulltext('name', 'dan', { diacriticsensitive false, casesensitive false }); 3 query sortbytextscore(); 4 let queryresult = await query find(); 5 console log(queryresult); seleção de campo esses métodos afetam quais valores de campo podem estar nos resultados da sua consulta exclude // return all fields in the returned objects except the ones specified 1 let query = new parse query('profile'); 2 query exclude('name'); 3 let queryresult = await query find(); 4 console log(queryresult\[0] get('name') === undefined); 5 console log(queryresult\[0] get('birthday')); include //includes nested parse objects for the provided key 1 let query = new parse query('profile'); 2 query exists('premiummembership'); 3 query include('premiummembership'); 4 let queryresult = await query find(); 5 console log(queryresult\[0] get('premiummembership')); includeall //includes all nested parse objects 1 let query = new parse query('profile'); 2 query exists('premiummembership'); 3 query includeall(); 4 let queryresult = await query find(); 5 console log(queryresult\[0] get('premiummembership')); select //return only the specified fields in the returned objects 1 let query = new parse query('profile'); 2 query select('name'); 3 let queryresult = await query find(); 4 console log(queryresult\[0] get('birthday') === undefined); 5 console log(queryresult\[0] get('name')); consulta de geoponto estes são métodos específicos para consulta de geoponto near // order objects by how near the key value is from the given geopoint 1 let query = new parse query('profile'); 2 query near('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 3 let queryresult = await query find(); 4 console log(queryresult); polygoncontains //find objects whose key value contains the specified geopoint 1 let query = new parse query('profile'); 2 query polygoncontains('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query withingeobox('lastloginlocation', new parse geopoint(37 48412167489413, 122 11268034622319), new parse geopoint(37 28412167489413, 121 91268034622319)); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query withinkilometers('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319), 100, true); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query withinmiles('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319), 60, true); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query withinpolygon('lastloginlocation', \[new parse geopoint(37 48412167489413, 122 11268034622319), new parse geopoint(37 48412167489413, 121 91268034622319), new parse geopoint(37 28412167489413, 121 91268034622319), new parse geopoint(37 28412167489413, 122 01268034622319)]); 3 let queryresult = await query find(); 4 console log(queryresult); 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 let query = new parse query('profile'); 2 query withinradians('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319), 1 5, true); 3 let queryresult = await query find(); 4 console log(queryresult); paginação esses métodos estão relacionados a utilitários de paginação, úteis para consultas que recuperarão um grande número de resultados limit // sets the maximum value of returned results, the default value is 100 1 let query = new parse query('profile'); 2 query limit(2); 3 let queryresult = await query find(); 4 console log(queryresult); skip //skips the first n results in the query, essential for pagination 1 let query = new parse query('profile'); 2 query skip(2); 3 let queryresult = await query find(); 4 console log(queryresult); withcount //sets a flag that will wrap or not the query response in an object containing results, holding the array of parse object and count integer holding the total number of results 1 let query = new parse query('profile'); 2 query withcount(true); 3 let queryresult = await query find(); 4 console log(queryresult); tratamento de resposta esses métodos são auxiliares para lidar com as respostas da consulta, tornando possível enfileirar callbacks que serão chamados após sua consulta ser resolvida eles atuam como resolutores de consulta também, como find find e first first each // iterates over each result from the query and calls a callback for each one, in an unspecified order note that execution will halt on a rejected promise, so make sure to handle this case if using promises 1 let query = new parse query('profile'); 2 let queryresult = await query each((result) => console log(result)); 3 console log(queryresult); eachbatch //iterates over each result from the query and calls a callback for each batch of results, in an unspecified order the batchsize value needs to be passed inside the options object parameter, being the default 100 note that execution will halt on a rejected promise, so make sure to handle this case if using promises 1 let query = new parse query('profile'); 2 let queryresult = await query eachbatch((result) => console log(result), {batchsize 2}); 3 console log(queryresult); filter //iterates over each result from the query and calls a callback for each one, in an unspecified order note that execution will halt on a rejected promise, so make sure to handle this case if using promises differs from each for passing more parameters down on callback execution 1 let query = new parse query('profile'); 2 let queryresult = await query filter((currentobject, index, query) => console log(`${index} ${currentobject} ${query}`)); 3 console log(queryresult); map //iterates over each result from the query and calls a callback for each one, in an unspecified order note that execution will halt on a rejected promise, so make sure to handle this case if using promises differs from each for passing more parameters down on callback execution 1 let query = new parse query('profile'); 2 let queryresult = await query map((currentobject, index, query) => console log(`${index} ${currentobject} ${query}`)); 3 console log(queryresult); reduce //iterates over each result from the query and calls a callback for each one, in an unspecified order note that execution will halt on a rejected promise, so make sure to handle this case if using promises differs from each for passing more parameters down on callback execution and by allowing direct accumulator handling the initialvalue is the value to use as the first argument to the first call of the callback if no initialvalue is supplied, the first object in the query will be used and skipped 1 let query = new parse query('profile'); 2 let queryresult = await query reduce((accumulator, currentobject, index) => console log(`${index} ${currentobject} ${accumulator}`)); 3 console log(queryresult); consulta composta esses métodos criarão consultas compostas, que podem combinar mais de uma parse query parse query instância para alcançar resultados mais complexos andquery // helper that is used by parse to add a constraint that all of passed in queries must match when using parse query and 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = new parse query('profile'); 6 query andquery(\[query1, query2]); 7 let queryresult = await query find(); 8 console log(queryresult); norquery //helper that is used by parse when using parse query nor 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = new parse query('profile'); 6 query norquery(\[query1, query2]); 7 let queryresult = await query find(); 8 console log(queryresult); orquery //helper that is used by parse to add a constraint that any of passed in queries must match when using parse query or 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = new parse query('profile'); 6 query orquery(\[query1, query2]); 7 let queryresult = await query find(); 8 console log(queryresult); and //compose a compound query that is the and of the passed queries 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = parse query and(query1, query2); 6 let queryresult = await query find(); 7 console log(queryresult); nor //compose a compound query that is the nor of the passed queries 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = parse query nor(query1, query2); 6 let queryresult = await query find(); 7 console log(queryresult); or //compose a compound query that is the or of the passed queries 1 let query1 = new parse query('profile'); 2 query1 greaterthan('friendcount', 10); 3 let query2 = new parse query('profile'); 4 query1 lessthan('friendcount', 50); 5 let query = parse query or(query1, query2); 6 let queryresult = await query find(); 7 console log(queryresult); banco de dados relacionado esses métodos estão relacionados a preferências e operações de banco de dados aggregate // executes an aggregate query, retrieving objects over a set of input values please refer to mongodb documentation on aggregate for better understanding 1 let query = new parse query('profile'); 2 let queryresult = await query aggregate({ limit 5 }); 3 console log(queryresult); explain //investigates the query execution plan, related to mongodb explain operation 1 let query = new parse query('profile'); 2 query explain(true); 3 let queryresult = await query find(); 4 console log(queryresult); readpreference //swhen using a mongodb replica set, use this method to choose from which replica the objects will be retrieved the possible values are primary (default), primary preferred, secondary, secondary preferred, or nearest 1 let query = new parse query('profile'); 2 query readpreference(''primary''); 3 let queryresult = await query find(); 4 console log(queryresult); armazenamento local esses métodos permitem selecionar a fonte das consultas e usar um armazenamento local fromlocaldatastore // changes the source of this query to all pinned objects 1 // this should be set before using fromlocaldatastore 2 parse enablelocaldatastore(); 3 let query = new parse query('profile'); 4 query fromlocaldatastore(); 5 let queryresult = await query find(); 6 console log(queryresult); fromnetwork //changes the source of this query to your online server 1 let query = new parse query('profile'); 2 query fromnetwork(); 3 let queryresult = await query find(); 4 console log(queryresult); frompin //changes the source of this query to the default group of pinned objects 1 let query = new parse query('profile'); 2 query frompin(); 3 let queryresult = await query find(); 4 console log(queryresult); frompinwithname //changes the source of this query to a specific group of pinned objects 1 let query = new parse query('profile'); 2 query frompinwithname('pinnedobjects'); 3 let queryresult = await query find(); 4 console log(queryresult); especificidades do json métodos que permitem que consultas sejam representadas como json e recuperadas tojson // returns a json representation of this query operations 1 let query = new parse query('profile'); 2 query greaterthan('friendcount', 10); 3 let queryjson = await query tojson(); 4 console log(queryjson); withjson //add a previously generated json representation of query operations to this query 1 let query = new parse query('profile'); 2 query greaterthan('friendcount', 10); 3 let queryjson = await query tojson(); 4 let query2 = new parse query('profile'); 5 query2 withjson(queryjson); 6 let queryresult = await query2 find(); 7 console log(queryresult); //static method to restore parse query by json representation, internally calling parse query withjson 1 let query = new parse query('profile'); 2 query greaterthan('friendcount', 10); 3 let queryjson = await query tojson(); 4 let query2 = parse query withjson('profile', queryjson); 5 let queryresult = await query2 find(); 6 console log(queryresult); conclusão no final deste guia, você aprendeu como realizar cada método de consulta de dados no parse no próximo guia, você aprenderá sobre consultas complexas no parse em react native