wood burning stoves 2.0*
The moose likes MongoDB and the fly likes Mongo aggregation framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » MongoDB
Bookmark "Mongo aggregation framework" Watch "Mongo aggregation framework" New topic

Mongo aggregation framework

vinny kapoor

Joined: Apr 05, 2008
Posts: 13
I wanted to write down my first query using spring's mongo aggregation framework. The query is basically to group by 'field' and then to count the number of occurences.

Something similar to

Select state, count(state)
from <table>
group by (state)

Corresponding query using mongo spring's framework using java:

TypedAggregation<Ticket> aggregation = newAggregation(Ticket.class, group("state").count().as("count"),

AggregationResults<cheese> results = springMongoManager.getDao().aggregate(aggregation, cheese.class);
List<cheese> mappedResults = results.getMappedResults();


class cheese {
String state;
long count;

The above query clearly is not working.

Any help will be appreciated.
It is sorta covered in the JavaRanch Style Guide.
subject: Mongo aggregation framework
Similar Threads
How to use regular expressions
Tell me this Logic
problem with "group by"
what is wrong in following EJBQL??
fetch Sum , count and entity with HQL + ClassCastException