IT/DB 2021. 6. 15.
mongodb - Flask mongoengine 필드 동일값을 그룹으로 묶기
저장된 데이터를 특정한 필드 값으로 그룹을 묶고 싶을때가 있다. 같은 값을 가진 문서가 몇개인지 궁금할 때가 가장 단순한 예가 되겠다. 이런 경우 aggregate 함수를 활용하면 된다. 몽고db 매뉴얼 페이지에서 해당 내용을 가져와 보자. https://docs.mongodb.com/manual/reference/operator/aggregation/sum/ Grouping the documents by the day and the year of the date field, the following operation uses the $sum accumulator to compute the total amount and the count for each group of documents. db.sales..