문서 메뉴

문서 홈가이드 시작

패싯으로 쿼리하기

In this guide, you will learn how to run a query with the facet collector to group your query results and returns the count for each of these groups.

소요 시간: 10분

1
2
샘플 데이터 클러스터
3
1
2

Create Index를 클릭합니다.

3

Select the Visual Editor configuration method, then click Next.

4
5

For the Database and Collection, select the sample_supplies database and the sales collection. Then, click Next.

6

Click Refine Your Index. In the Index Configuration pane, toggle off Dynamic Mapping.

7

In the Field Mappings pane, click Add Field Mapping. In the modal window, select purchaseMethod from the Field Name dropdown menu.

8

From the Data Type dropdown menu, select String. Click Add at the bottom of the modal window. Leave the Index Configurations values unchanged, and click Add at the bottom of the modal window.

9

In the Field Mappings pane, click Add Field Mapping. In the modal window, select storeLocation from the Field Name dropdown menu.

10

From the Data Type dropdown, select StringFacet. Click Add at the bottom of the modal window.

4
1

Aggregation 탭을 클릭합니다.

2

Click + Add Stage to begin creating your aggregation pipeline.

3

In the stage window, click on the dropdown menu labeled Select... and select the $searchMeta stage.

4

Replace the placeholder code with the following query.

{
"facet": {
"operator": {
"text": {
"query": ["In store"],
"path": "purchaseMethod"
}
},
"facets": {
"locationFacet": {
"type": "string",
"path": "storeLocation",
}
}
}
}

This query uses the facet collector with:

  • The text operator to count only documents with a purchaseMethod value of In store.

  • The facet named locationFacet that creates a bucket for each different storeLocation value.

5

Your results should resemble the following sample document, which is shown partially expanded:

count: Object
lowerBound: 2819
facet: Object
locationFacet: Object
buckets: Array
0: Object
id: "Denver"
count: 864
1: Object
id: "Seattle"
count: 648
2: Object
3: Object
4: Object
5: Object

You can expand Array and Object fields to view their contents by clicking on them.

If you successfully completed the procedure in this guide, you have created an Atlas Search index with faceting and created an aggregation pipeline that leverages faceting to organize matching records into categories for improved visibility.

마지막으로
Become a MongoDB Professional

Congrats. You’ve completed all the guides. Want to take the next step? Register for the developer exam.

자세히 알아보기
3장
Atlas Search
  • 동적 인덱스 빌드하기
  • 정적 필드 매핑으로 인덱스 빌드하기
  • 복합 연산자로 쿼리하기
  • 패싯으로 쿼리하기
가이드 시작 →