• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mongo aggregation framework

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"),
project("state").and("count").previousOperation());

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


where

class cheese {
String state;
long count;
}


The above query clearly is not working.

Any help will be appreciated.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic