Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group (By) in Mongoose?

I've constructed the query I want in the shell but am having trouble writing it in Mongoose.

db.commentstreams.group({ key: { page_id: true }, reduce: function(obj,prev) { prev.num_comments += obj.num_comments }, initial: { num_comments: 0 } })

I'm a bit confused by the Mongoose syntax; perhaps someone could shed some light on this one. Much thanks.

like image 639
mponizil Avatar asked Jul 27 '11 23:07

mponizil


1 Answers

According to this post:

Model.find({}, [fields], {'group': 'FIELD'}, function(err, logs) { 
        ... 
}); 

Unfortunately we seem to be lacking documentation for this one.

like image 141
andyuk Avatar answered Oct 05 '22 00:10

andyuk