MongoDB group query works in terminal, throws error in nodejs file

Problem

I've got a query that works fine in the terminal querying my mongodb collection, however inside of the function that I want to group the data, I'm getting the following error:

// QUERY WORKS:
/*
> db.twitterhashtags.group({ key: {"text":true}, initial: {sum:0}, reduce: function(doc, prev) {prev.sum +=1}});
 [
{
    "text" : "spnyc",
    "sum" : 1
},
{
*/
//RUNNING QUERY CAUSES THIS ERROR:
// TypeError: undefined is not a function
// at Collection.group.scope (/Users/propstm/Projects/nodeproject/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/collection.js:1341:16)
//at g (events.js:185:14)

This is the line of code that throws the error shown above.

db.collection("twitterhashtags").group({ key: {"text":true}, initial: {sum:0}, reduce: function(doc, prev) {prev.sum +=1}});
Problem courtesy of: propstm

Solution

the driver is not following the console convention 100%. The docs have examples of using group.

http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#group

However if it's a new app and you are using 2.2 you should not use group unless you have to and use the aggregation framework instead.

http://docs.mongodb.org/manual/aggregation/

Solution courtesy of: christkv

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.