# 23. 리뷰 평점을 계산하고 싶어요.

{% hint style="info" %}
고급자를 위한 가이드에요.

메타, 항목 id, 데이터 구조의 이해가 잡히신 분들께 추천드려요.
{% endhint %}

리뷰 평점을 계산하는 것처럼 특정 문서들을 계산해야 할 때가 있어요.

계산하는 방법은 서비스, 앱 구조, 화면에 따라 정말 다양하니 현 상황에 알맞은 방법을 잘 골라야 해요.

여기서는 그중 1가지 방법을 소개 드릴게요.

```json
"collectionOptions": {
		"joinSummaries": [
			{
				"id": "reviewInfo", // id 정의
				"items": [
					{
						"id": "avg",
						"targetItem": "rating", // 평균을 구할 항목
						"type": "#avg" // 평균을 구하는 메서드
					},
					{
						"id": "size",
						"type": "#size" // 총 개수를 구하는 메서드
					}
				],
				"joinMeta": "pkg_categoryMap_review", // 참조할 메타
				"joinOptions": {
					"as": {
						"joinMetaName": "restaurantReview", // 참조할 메타 정의
						"metaName": "restaurant" // 현재 메타 정의
					},
					"filters": [
						{
							"#eq": {
								"#left": "restaurant._id", // 현재 메타의 _id
								"#right": "restaurantReview.storeJoin._id" // 참조 메타의 storeJoin._id
							}
						}
					]
				}
			}
		]
	}
```

**reviewInfo.avg** : 평균

**reviewInfo. size**: 리뷰 개수

위 코드를 복사해서 사용할 메타의 documentMeta 안에 붙여 넣어 주세요.

메타 코드를 보는 법은 이 [가이드](https://docs.ohmyapp.io/main/guide/dictionary/collection-name)를 참고해 주세요.

<div align="left"><figure><img src="https://3976660509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDgfvhQgmY9NbRK0Sln7j%2Fuploads%2FiMNCzoolSeSTC5x6pfnY%2Fimage.png?alt=media&#x26;token=851e774c-d2d0-4525-8336-878c4b200b53" alt="" width="334"><figcaption></figcaption></figure></div>

24.08.02 Jihwan
