codestates / codestates/Lumiere
[Dev-Log] 진가람 2021-12-18
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
> ### 오늘은 어떻게 프로젝트에 기여했나요?
> - #513
> - #532
> - #543
> - 디비 데이터 추가
> - 테스트
> ### 오늘의 프로젝트에서 힘든 점은 무엇인가요?
> - 오늘 새로이 알게된 $facet
>> $count aggregation will always give you the counts for only single matching ($match) condition.
So you need to further divide your each count into multiple section and that's what the $facet provides
by processes multiple aggregation pipelines within a single stage on the same set of input documents.
> - 프로젝트 막바지에 알게됐지만, 알게돼서 정말 다행이다!!
$facet 덕분에 하나의 쿼리에 여러 개의 파이프라인을 나열해서 한번에 여러 기준의 그룹핑 기능을 수행할 수 있었다.
찾아보니 특히 쇼핑몰처럼 다양한 기준별로 상품의 갯수를 그룹핑해서 보여주고, 특정 그룹을 또 다시 하위의 다른 기준으로
그룹핑해서 보여주는 기능에 매우 고마운 메소드인 것 같다.
> - 이런 기능을 "Facet Query" 라 하는데,
일반적인 RDBMS에서는 하나의 쿼리로 다양한 기준의 그룹핑 쿼리를 수행할 수 없다는 아주 기분좋은 정보를 찾아냈다!!
바로 E-Commerce에 문서형 몽고디비를 사용해야하는 또 다른 중요한 이유를 찾아냈다!!
>> MongoDB 3.4 버전부터 $facet 스테이지를 이용해서 상품을 가격대별로 그리고 카테고리 별로 한번에 그룹핑해서 개수를 가져올 수 있다.
```js
const status = await Order.aggregate([
{
$facet: {
paid: [{ $match: { 'result.status': { $eq: 0 } } }, { $count: 'paid' }],
ready: [{ $match: { 'result.status': 1 } }, { $count: 'ready' }],
coming: [{ $match: { 'result.status': 2 } }, { $count: 'coming' }],
done: [{ $match: { 'result.status': 3 } }, { $count: 'done' }],
},
},
{
$project: {
paid: { $arrayElemAt: ['$paid.paid', 0] },
ready: { $arrayElemAt: ['$ready.ready', 0] },
coming: { $arrayElemAt: ['$coming.coming', 0] },
done: { $arrayElemAt: ['$done.done', 0] },
},
},
]);
```
>
> ### 내일은 프로젝트에 기여하기 위해 무엇을 해야 하나요?
> - [x] 배포된 것으로 버그 체크하기
> - [x] 개인 기술 발표 자료 찾고 공부하기
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.