how do .group()?

3,463 views
Skip to first unread message

AbS_

unread,
Mar 3, 2011, 5:34:51 PM3/3/11
to Mongoose Node.JS ORM
Hi,
How i can do something like this:
db.posts.group({key: {region:true}, $reduce: function(){}, initial:
{}})

on Mongoose?

Marc Harter

unread,
Mar 26, 2011, 11:35:49 PM3/26/11
to mongoo...@googlegroups.com, AbS_
I have the same question.  This possible, digging into the docs and code base couldn't find anything.  My gut is just do separate queries for each 'group'.  Can anyone shine some light on this?

Jeroen Bourgois

unread,
Apr 8, 2011, 3:44:49 AM4/8/11
to Mongoose Node.JS ORM
Yes, I would need it to. Any updates on how to achieve this? Makes a
big difference if you have to get +5000 documents from the db, filter
them in your app and do the grouping yourself. Really slow :(

Jeroen Bourgois

unread,
Apr 10, 2011, 4:11:54 PM4/10/11
to Mongoose Node.JS ORM
Got it!

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

Florian Pfitzer

unread,
Jun 4, 2011, 8:21:02 AM6/4/11
to Mongoose Node.JS ORM
Is this still working with 1.3.7?

I have list of People and I want them to be grouped by lastname, so i
did:

People.find({},[],{'group': 'lastname'},function(err,people){
...
});

But it returns the same like:

People.find({},function(err,people){
...
});

and there is no error.

Láďa Říha

unread,
Mar 4, 2012, 11:38:00 AM3/4/12
to mongoo...@googlegroups.com
Bump... Has anyone achive that in version 2.5.x?

一回

unread,
Mar 14, 2012, 10:05:02 AM3/14/12
to Mongoose Node.JS ORM
you can use this:

Model.collection.group(keys, condition, initial, reduce, finalize,
command, callback);
Reply all
Reply to author
Forward
0 new messages