what is different between mapReduce and aggregation function?

856 views
Skip to first unread message

jamesKim

unread,
Mar 8, 2012, 11:35:23 PM3/8/12
to mongodb-user
what is different between mapReduce and aggregation function?
my example

1.aggregation group function
db.pageviews.group(
{
key: {'user.agent': true},
initial: {sum: 0},
reduce: function(doc, prev) { prev.sum += 1}
});


2.using mapreduce
db.runCommand({mapreduce:"pageviews",......)

when i wanna get a sum propertie. is it different 1. and 2.?



Nat

unread,
Mar 8, 2012, 11:50:17 PM3/8/12
to mongod...@googlegroups.com
Hi,
 
group command is for basic aggregation where you can't control how to emit the key. The key will be emitted as is as you specify in "key" parameter. mapReduce allows advanced aggregation where you can specify the logic for key emitting. group command is a little bit faster for the same operation (if it can be done using group())
Reply all
Reply to author
Forward
0 new messages