Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Aggregate Functions

Tags:

mongodb

I am trying to do a group by on a MongoDB collection (my version is 2.2.2)

db.stream.aggregate({$group: { MyId:"A1"}})

But I get the following error:

19 11:56:20 TypeError: db.stream.aggregate is not a function (shell):1

Many Thanks,

like image 458
DafaDil Avatar asked May 19 '13 11:05

DafaDil


1 Answers

You must be using 2.2.+ version of the shell to be able to use the aggregate helper.

You can check the shell version with version() command at the shell prompt.

In addition, your aggregation syntax is incorrect - the $group operator must set a field called _id (you have MyId) which is what tells it which field you are aggregating by.

like image 149
Asya Kamsky Avatar answered Oct 13 '22 03:10

Asya Kamsky