Group (By) in Mongoose?


Question

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.

1
19
7/28/2011 3:24:12 AM

According to this post:

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

Unfortunately we seem to be lacking documentation for this one.

14
9/27/2011 1:37:36 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon