ReactJS
Data objects
Parseクエリガイド: Reactアプリでのデータ取得方法
20 分
parseのためのreact query cookbook はじめに 私たちはすでに、 parse query parse query を使って、 get get を使って、 parse object parse object をback4appから取得する方法を見てきました。他にも、 parse query parse query を使ってデータを取得する方法はたくさんあります 一度に多くのオブジェクトを取得したり、取得したいオブジェクトに条件を付けたり、その他多くのことができます。 このガイドでは、 parse query parse query クラスを深く掘り下げ、クエリを構築するために使用できるすべてのメソッドを確認します。シンプルなデータベースクラスといくつかのモックデータを使用して、back4appのjavascriptコンソールを使ってクエリを実行します。 前提条件 このチュートリアルを完了するには、次のものが必要です アプリ back4appで作成された 目標 さまざまなメソッドを持つ parse query parse query クラスを探求します。 parse queryクラス parseでの任意のクエリ操作は、 parse query parse query オブジェクトタイプを使用し、アプリ全体でback4appから特定のデータを取得するのに役立ちます。新しい parse query parse query を作成するには、取得したい parse object parse object サブクラスをパラメータとして渡す必要があります。これは、クエリ結果を含むものです。 重要なのは、 parse query parse query は、retrieveメソッド(例えば、 parse query find parse query find や parse query get parse query get )を呼び出した後にのみ解決されることを知っておくことが重要です。したがって、クエリを設定し、実際に呼び出される前にいくつかの修飾子をチェーンすることができます。 より詳しい情報は、 parse query parse query クラスについては、 公式ドキュメントのこちらをご覧ください https //parseplatform org/parse sdk js/api/master/parse query html 。 back4appでのjsコンソールの使用 back4appアプリケーションのダッシュボード内には、javascriptコードを直接実行できる非常に便利なapiコンソールがあります。このガイドでは、back4appからデータオブジェクトを保存およびクエリするために使用します。アプリのメインダッシュボードで、 core >api console >js console core >api console >js console に移動します。 データオブジェクトを保存する このガイドでクエリを実行するには、まずアプリにデータを入力する必要があります。サンプルクラス「 プロフィール プロフィール 」を作成しましょう。これは、有名人の名前を使用してソーシャルメディアのプロフィールクラスを模倣し、次のフィールドを持ちます 文字列型 名前 名前 ; 日付型 誕生日 誕生日 ; 数値(整数)型 友達の数 友達の数 ; 配列(文字列配列)型 好きな食べ物 好きな食べ物 ; 配列(数値配列)型 ラッキーナンバー ラッキーナンバー ; ジオポイント型 最終ログイン場所 最終ログイン場所 ; ヌル許容ポインタ型 プレミアムメンバーシップ プレミアムメンバーシップ , に関連する メンバーシップ メンバーシップ クラスには、文字列 名前 名前 と日付 有効期限 有効期限 フィールドがあります。 ここに parse object parse object クラスの作成コードがありますので、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!'); このコードを実行した後、データベースに6つのオブジェクトが作成された profile profile クラスがあるはずです。新しいクラスは次のようになります 次に、すべての parse query parse query メソッドの例を見て、それらが何をするのかについて簡単な説明をします。このリストのいくつかのメソッドは、追加の引数として options options を取ることができますが、ほとんどの場合、それは masterkey masterkey の使用に関連しており、このガイドの内容には関係ありませんので、関連しない場合はこの可能性を省略します。 クエリリトリーバー これらのメソッドは、クエリを実行し、その結果を取得する責任があり、常にクエリの実装に存在します。 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); 	 クエリ条件 これらのメソッドは、クエリに条件付き制約を適用する可能性を提供します。これは、クエリにおいて最も重要な操作といえるでしょう。これらの操作はすべて、結果が取得される前にチェーンすることができるため、クエリのニーズを解決するために多くの組み合わせを実現できます。 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'); 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); クエリの順序 ほとんどのクエリにおいて不可欠であり、順序付けはparseで簡単に実現でき、2つ以上の順序制約の間でチェーンすることもできます。 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); フィールド選択 これらのメソッドは、クエリ結果に含まれるフィールド値に影響を与えます。 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')); ジオポイントクエリ これらはジオポイントクエリに特有のメソッドです。 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); ページネーション これらのメソッドは、結果が大量に返されるクエリに便利なページネーションユーティリティに関連しています。 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); レスポンス処理 これらのメソッドは、クエリ応答を処理するためのヘルパーであり、クエリが解決された後に呼び出されるコールバックをキューに入れることを可能にします。彼らはまた、クエリ解決者としても機能します。例えば、 find find と 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); 複合クエリ これらのメソッドは複合クエリを作成し、複数の parse query parse query インスタンスを組み合わせて、より複雑な結果を得ることができます。 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); データベース関連 これらの方法は、データベースの設定と操作に関連しています。 aggregate // executes an aggregate query, retrieving objects over a set of input values please refer to mongodb documentation on aggregate(https //docs mongodb com/v3 2/reference/operator/aggregation/)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 // when 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); ローカルデータストア これらのメソッドは、クエリのソースを選択し、ローカルデータストアを使用することを可能にします。 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); jsonの特性 クエリをjsonとして表現し、取得することを可能にするメソッド。 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); 結論 このガイドの最後に、parseでのすべてのデータクエリメソッドを実行する方法を学びました。次のガイドでは、reactにおけるリレーショナルparseクエリについて学びます。