MVP online tool
SQL to MongoDB
관계형 SQL SELECT query를 MongoDB find 또는 aggregation pipeline 초안으로 변환합니다. JOIN과 집계는 자동 변환 결과와 함께 검토 포인트를 표시합니다.
Conversion status
Converted with warnings
Mode
aggregate
Collection
customers
Stages
8
Input SQL
SELECT query만 MVP 범위로 지원합니다.
JOIN, GROUP BY, aggregate function 중 하나가 있어 aggregation pipeline을 생성했습니다.
MongoDB Output
Mongo shell compatible draft
db.customers.aggregate(
[
{
"$lookup": {
"from": "orders",
"localField": "customer_id",
"foreignField": "customer_id",
"as": "o"
}
},
{
"$unwind": {
"path": "$o",
"preserveNullAndEmptyArrays": false
}
},
{
"$match": {
"status": "active",
"o.created_at": {
"$gte": "2026-01-01"
}
}
},
{
"$group": {
"_id": {
"customer_id": "$customer_id",
"name": "$name"
},
"order_count": {
"$sum": 1
},
"total_spend": {
"$sum": "$o.total"
}
}
},
{
"$match": {
"order_count": {
"$gt": 3
}
}
},
{
"$project": {
"_id": 0,
"customer_id": "$_id.customer_id",
"name": "$_id.name",
"order_count": "$order_count",
"total_spend": "$total_spend"
}
},
{
"$sort": {
"total_spend": -1
}
},
{
"$limit": 20
}
]
);