K
KRYFT Problem Bank
데이터베이스 보통 코딩

MongoDB 집계 파이프라인

MongoDB Aggregation으로 복잡한 쿼리

35분
80점
#3736

문제 설명

MongoDB의 Aggregation Pipeline을 사용하여 다음 쿼리들을 작성하세요.

컬렉션 구조


// orders
{
  _id: ObjectId,
  customerId: ObjectId,
  items: [
    { productId: ObjectId, name: String, price: Number, quantity: Number }
  ],
  status: String,  // "pending", "completed", "cancelled"
  createdAt: Date
}

// customers
{
  _id: ObjectId,
  name: String,
  email: String,
  tier: String,  // "bronze", "silver", "gold"
  joinedAt: Date
}

작성할 쿼리

  1. 월별 매출 집계 (year, month, totalRevenue, orderCount)
  2. 고객 등급별 평균 주문 금액
  3. 가장 많이 팔린 상품 Top 10
  4. 최근 3개월 신규 고객의 첫 주문 평균 금액
  5. 재구매율이 높은 상품 (2회 이상 구매된 상품)

평가 기준

  • 파이프라인 효율성
  • 인덱스 활용
  • 결과 정확성
실행 버튼을 눌러 코드를 실행하세요.