Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dev-Log] 진가람 2021-12-18 #534

Open
heartane opened this issue Dec 18, 2021 · 0 comments
Open

[Dev-Log] 진가람 2021-12-18 #534

heartane opened this issue Dec 18, 2021 · 0 comments
Assignees
Labels
dev-log dev 로그 작성시 사용하는 라벨

Comments

@heartane
Copy link
Collaborator

heartane commented Dec 18, 2021

오늘은 어떻게 프로젝트에 기여했나요?

오늘의 프로젝트에서 힘든 점은 무엇인가요?

  • 오늘 새로이 알게된 $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 스테이지를 이용해서 상품을 가격대별로 그리고 카테고리 별로 한번에 그룹핑해서 개수를 가져올 수 있다.

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] },
      },
    },
  ]);

내일은 프로젝트에 기여하기 위해 무엇을 해야 하나요?

  • 배포된 것으로 버그 체크하기
  • 개인 기술 발표 자료 찾고 공부하기
@heartane heartane added the dev-log dev 로그 작성시 사용하는 라벨 label Dec 18, 2021
@heartane heartane self-assigned this Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-log dev 로그 작성시 사용하는 라벨
Projects
None yet
Development

No branches or pull requests

1 participant