Aggregation pipelines transform your documents into an aggregated set of results. In Atlas Charts, aggregation pipelines are commonly used to visualize new fields created from calculated results of pre-existing fields, but also have many other applications.
집계 파이프라인을 생성하려면 다음을 수행합니다.
Query 막대에 집계 파이프라인을 입력합니다. 파이프라인은 대괄호 안에 넣어야 합니다.
(선택 사항) Format 을 선택하여 쿼리를 다음과 같이 정렬합니다.
쿼리를 여러 줄로 분할
JSON 규칙에 따라 쿼리를 들여쓰기합니다.
(조건부) Format 옵션을 선택한 경우 완료되면 Close를 클릭합니다.
파이프라인을 실행하려면 Apply를 클릭합니다.
예시
다음 차트는 한 사무용품 회사의 총 판매 금액을 매장 위치별로 분류한 것입니다. 차트에서는 Query 표시줄에서 다음 집계 파이프라인을 사용합니다.
[ { $unwind: "$items" }, { $addFields: { saleAmount: { $multiply: [ "$items.price", "$items.quantity" ] } } } ]
이 집계 파이프라인은 다음 순서에 따라 컬렉션 데이터를 처리합니다.
The
$unwindstage unwinds theitemsarray and outputs a new document for each item in the array. Each element in theitemsarray contains a single item sold during a transaction.The
$addFieldsstage adds a new field to the documents calledsaleAmount. The$multiplyexpression sets the value ofsaleAmountto the product ofitems.priceanditems.quantity. You can see this new field highlighted in the following screenshot:

파이프라인을 사용하여 데이터가 처리되면 차트에 매장 위치별로 분류된 모든 saleAmounts의 Sum이 표시됩니다.
집계 파이프라인 오류 해결
집계가 유효하지 않은 경우 차트는 Query 표시줄에 아이콘을 표시합니다.
오류 세부 정보를 보려면 Query 표시줄이 아직 표시되지 않은 경우 이를 클릭합니다. Charts는 다음 오류 세부 정보를 표시합니다:
잘못된 JSON과 같은 클라이언트 사이드 오류
잘못된 MQL 또는 지원되지 않는 파이프라인 단계와 같은 서버 측 오류입니다.

오류 세부 정보를 검토한 후 그에 따라 집계 파이프라인을 조정합니다.
제한 사항
Charts doesn't support the
$lookupoperator in aggregation queries. However, you can use this operator in Data Source pipelines. To learn more about how to use pipelines to pre-process data before it reaches the Chart Builder, see Create and Manage Charts Views.Charts supports the
$functionoperator only when you define the function body in a single line and wrap it in double quotes. To use this operator in your aggregation queries, you must use the following syntax:{ $function: { body: "function(arg1, arg2, ...) { ... }", args: <array expression>, lang: "js" } }