MongoDB 2.2 introduces "aggregation framework", official definition - operations that process data records and return computed results. For easier understanding, imagine a bucket contains good and bad apples and oranges, I can use aggregation framework to get a quick result on a total of good apples and oranges.
From a SQL query point of view:
SQL query
SELECT cust_id, SUM(price) FROM orders
WHERE active=true
GROUP BY cust_id
MongoDB Aggregation
db.orders.aggregate( [
{ $group: { _id: "$cust_id", total: {$sum: "$price" } }
} ] )
No comments:
Post a Comment