$sort연산자에서 필드 값이 -1 이면 내림차순 정렬, 1이면 오름차순 정렬을 수행함.
ex. mongoDB
db.order.aggregate([{$group:
{_id:"$cust_id",
total_price:{$sum:"$price"}}},
{$sort:{total_price:-1}}]);
ex. oracle sql
SELECT cust_id AS "_id", SUM(price) AS "total_price"
FROM order
GROUP BY cust_id
ORDER BY "total_price" DESC;
위 위 mongoDB 질의와 아래 sql 질의는 같은 결과.