---
title: React 애플리케이션에서 Parse 쿼리 메서드 사용법
slug: docs-kr/react/data-objects/react-query-cookbook
description: Parse.Query 클래스를 사용하여 React 애플리케이션에서 데이터 쿼리를 최적화하는 방법을 알아보세요.
image: https://www.back4app.com/images/logo-social.png
createdAt: 2024-03-18T20:50:59.982Z
---

# Parse를 위한 React Query 요리책

## 소개

우리는 이미 <font color="#2166ae">`Parse.Query`</font>를 사용하여 <font color="#2166ae">`get`</font>를 통해 단일 <font color="#2166ae">`Parse.Object`</font>를 Back4App에서 검색하는 방법을 보았습니다. <font color="#2166ae">`Parse.Query`</font>를 사용하여 데이터를 검색하는 다른 많은 방법이 있습니다 - 여러 객체를 한 번에 검색하거나, 검색하려는 객체에 조건을 사용할 수 있습니다.

이 가이드에서는 <font color="#2166ae">`Parse.Query`</font> 클래스에 대해 깊이 파고들고, 쿼리를 구축하는 데 사용할 수 있는 모든 메서드를 살펴볼 것입니다. Back4App의 Javascript Console을 사용하여 쿼리를 수행하기 위해 일부 모의 데이터가 포함된 간단한 데이터베이스 클래스를 사용할 것입니다.

## 전제 조건

:::hint{type="info"}
이 튜토리얼을 완료하려면 다음이 필요합니다:

-  앱 [Back4App에서 생성된](https://www.back4app.com/docs/get-started/new-parse-app).
:::

### 목표

다양한 메서드를 가진 <font color="#2166ae">`Parse.Query`</font> 클래스를 탐색합니다.

### Parse.Query 클래스

Parse에서의 모든 쿼리 작업은 <font color="#2166ae">`Parse.Query`</font> 객체 유형을 사용하며, 이는 앱 전반에 걸쳐 Back4App에서 특정 데이터를 검색하는 데 도움이 됩니다. 새로운 <font color="#2166ae">`Parse.Query`</font>를 생성하려면 원하는 <font color="#2166ae">`Parse.Object`</font> 하위 클래스를 매개변수로 전달해야 하며, 이는 쿼리 결과를 포함할 것입니다.

쿼리는 <font color="#2166ae">`Parse.Query`</font>를 호출한 후에만 해결된다는 것을 아는 것이 중요합니다 (예: <font color="#2166ae">`Parse.Query.find`</font> 또는 <font color="#2166ae">`Parse.Query.get`</font>), 따라서 쿼리를 설정하고 실제로 호출되기 전에 여러 수정자를 연결할 수 있습니다.

더 많은 정보는 <font color="#2166ae">`Parse.Query`</font> 클래스에 대해 [공식 문서에서 여기](https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Query.html)에서 확인할 수 있습니다.

## Back4App에서 JS 콘솔 사용하기

Back4App 애플리케이션 대시보드 내에서 JavaScript 코드를 직접 실행할 수 있는 매우 유용한 API 콘솔을 찾을 수 있습니다. 이 가이드를 사용하여 Back4App에서 데이터 객체를 저장하고 쿼리할 것입니다. 앱의 주요 대시보드에서 <font color="#2166ae">`Core->API Console->JS Console`</font>으로 이동하세요.

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/2YJSIqySaVbv0UDA4WtHp_image.png)

## 데이터 객체 저장하기

이 가이드에서 쿼리를 실행하려면 먼저 앱에 데이터를 채워야 합니다. 유명인 이름과 다음 필드를 사용하여 소셜 미디어 프로필 클래스를 모방하는 샘플 클래스를 만들어 보겠습니다.<font color="#2166ae">`프로필`</font>, 다음과 같은 필드가 포함됩니다:

- 문자열 유형 <font color="#2166ae">`이름`</font>;
- 날짜 유형 <font color="#2166ae">`생일`</font>;
- 숫자(정수) 유형 <font color="#2166ae">`친구 수`</font>;
- 배열(문자열 배열) 유형 <font color="#2166ae">`좋아하는 음식`</font>;
- 배열(숫자 배열) 유형 <font color="#2166ae">`행운의 숫자`</font>;
- GeoPoint 유형 <font color="#2166ae">`마지막 로그인 위치`</font>;
- Nullable 포인터 유형 <font color="#2166ae">`프리미엄 멤버십`</font>, 관련된 <font color="#2166ae">`멤버십`</font> 클래스는 문자열 <font color="#2166ae">`이름`</font>과 날짜 <font color="#2166ae">`만료 날짜`</font> 필드를 포함합니다.

여기 <font color="#2166ae">`Parse.Object`</font> 클래스 생성 코드가 있으니, API 콘솔에서 실행해 보세요:

```javascript
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!');

```

이 코드를 실행한 후, 데이터베이스에 여섯 개의 객체가 생성된 <font color="#2166ae">`프로필` </font>클래스가 있어야 합니다. 새 클래스는 다음과 같아야 합니다:

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/azwzv3mzfo1D70FbLHziz_image.png)

이제 모든 <font color="#2166ae">`Parse.Query`</font> 메서드의 예를 살펴보고, 그들이 하는 일에 대한 간단한 설명을 추가하겠습니다. 이 목록의 일부 메서드는 <font color="#2166ae">`옵션` </font>을 추가 인수로 받을 수 있지만, 대부분의 경우 이는 <font color="#2166ae">`masterKey` </font> 사용과 관련이 있으며, 이 가이드 내용과는 관련이 없으므로 관련이 없는 경우 이 가능성은 생략됩니다.

## 쿼리 검색기

이 방법들은 쿼리를 실행하고 그 결과를 검색하는 책임이 있으며, 항상 쿼리 구현에 존재합니다.

:::CodeblockTabs
cancel

```javascript
// 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

```javascript
// 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

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```

&#x20;first

```javascript
// 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

```javascript
// 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);		
```
:::

## 쿼리 조건자

이 방법들은 쿼리에 조건부 제약을 적용할 수 있는 가능성을 제공합니다. 이는 쿼리에서 가장 중요한 작업이라고 할 수 있습니다. 이러한 작업은 결과가 검색되기 전에 모두 연결할 수 있으므로, 쿼리 요구 사항을 해결하기 위해 많은 조합을 달성할 수 있습니다.

:::CodeblockTabs
\_addCondition

```javascript
// 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

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```
:::

:::CodeblockTabs
contains

```javascript
// 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);
```

&#x20;containsAll

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```
:::

:::CodeblockTabs
doesNotMatchKeyInQuery

```javascript
// 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);
```

&#x20;doesNotMatchQuery

```javascript
// 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);
```

&#x20;endsWith

```javascript
// 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

```javascript
// 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);
```
:::

:::CodeblockTabs
exists

```javascript
// 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);
```

&#x20;fullText

```javascript
// 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);
```

&#x20;greaterThan

```javascript
// 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

```javascript
// 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);
```
:::

:::CodeblockTabs
lessThan

```javascript
// 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

```javascript
// 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);
```

&#x20;matches

```javascript
// 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

```javascript
// 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);
```
:::

:::CodeblockTabs
matchesQuery

```javascript
// 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

```javascript
// 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);
```

&#x20;startsWith

```javascript
// 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에서 정렬을 쉽게 수행할 수 있으며 두 개 이상의 정렬 제약 조건 간에 체인할 수도 있습니다.

:::CodeblockTabs
addAscending

```javascript
// 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

```javascript
// 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

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```
:::

## 필드 선택

이 메서드는 쿼리 결과에 포함될 수 있는 필드 값을 결정합니다.

:::CodeblockTabs
exclude

```javascript
// 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

```javascript
// 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'));
```

&#x20;includeAll

```javascript
// 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'));
```

&#x20;select

```javascript
// 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'));
```
:::

## 지오포인트 쿼리

이것은 지오포인트 쿼리에 특정한 방법입니다.

:::CodeblockTabs
near

```javascript
// 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

```javascript
// 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);
```

&#x20;withinGeoBox

```javascript
// 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);
```

&#x20;withinKilometers

```javascript
// 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);
```
:::

:::CodeblockTabs
withinMiles

```javascript
// 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

```javascript
// 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);
```

&#x20;withinRadians

```javascript
// 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);
```
:::

## 페이지 매김

이 방법들은 많은 결과를 검색하는 쿼리에 유용한 페이지 매김 유틸리티와 관련이 있습니다.

:::CodeblockTabs
limit

```javascript
// 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

```javascript
// 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);
```

&#x20;withCount

```javascript
// 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);
```
:::

## 응답 처리

이 방법들은 쿼리 응답을 처리하기 위한 도우미로, 쿼리가 해결된 후 호출될 콜백을 큐에 추가할 수 있게 해줍니다. 이들은 또한 <font color="#2166ae">`find` </font>와 <font color="#2166ae">`first`</font>와 같은 쿼리 해결자로 작용합니다.

:::CodeblockTabs
each

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```

&#x20;map

```javascript
// 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

```javascript
// 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);
```
:::

## 복합 쿼리

이 방법들은 복합 쿼리를 생성하며, 이는 하나 이상의 <font color="#2166ae">`Parse.Query` </font> 인스턴스를 결합하여 더 복잡한 결과를 얻을 수 있습니다.

:::CodeblockTabs
\_andQuery

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```

&#x20;and

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```
:::

## 데이터베이스 관련

이 방법들은 데이터베이스 설정 및 작업과 관련이 있습니다.

:::CodeblockTabs
aggregate

```javascript
// 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

```javascript
// 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);
```

&#x20;readPreference

```javascript
// 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);
```
:::

## 로컬 데이터 저장소

이 방법은 쿼리의 소스를 선택하고 로컬 데이터 저장소를 사용할 수 있게 합니다.

:::CodeblockTabs
fromLocalDatastore

```javascript
// 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

```javascript
// 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

```javascript
// 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);
```

&#x20;fromPinWithName

```javascript
// 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으로 표현하고 검색할 수 있는 메소드입니다.

:::CodeblockTabs
toJSON

```json
// 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

```json
// 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 쿼리에 대해 배울 것입니다.
