is it possible to have pivot in spring-data-mongodb? -


i new mongodb , spring data, , experimenting mongodb, possible have pivot operation mentioned pivot in mongodb using spring data. have data of form:

 name| sumprice| type|year   a|    50.0|     retail|2015  b|    467.0|    online|2015  a|    1456.0|   direct|2015  b|    1149.53|  direct|2015  c|     273.20|  online|2014  c|     110.0|   direct|2014 

for created java class :

    class samplereport{       private string name;      private double sumunitprice;      private string type;      private integer year;       }  

i want pivot w.r.t. type , want data of form :

  name |retail| online | direct| year   a|     50.0 |  0.0|    1456.0 |    2015   b|     0.0|    467.0|  1149.53|  2015   c|     0.0|    273.20| 110.0|     2014 

the example mentioned in spring data web site not clear me or complex understanding, please lemme know how same above example spring-data. answers

regards

kris

as linked, answer there.

using spring smth like:

 class zipinfo {     string id;     string city;     string state;     @field("pop") int population;     @field("loc") double[] location;  }   class city {    string name;    int population;  }  class zipinfostats {     string id;     string state;     city biggestcity;     city smallestcity;  }  typedaggregation<zipinfo> aggregation = newaggregation(zipinfo.class,     group("state", "city")         .sum("population").as("pop"),     sort(asc, "pop", "state", "city"),     group("state")        .last("city").as("biggestcity")        .last("pop").as("biggestpop")        .first("city").as("smallestcity")        .first("pop").as("smallestpop"),     project()        .and("state").previousoperation()        .and("biggestcity")        .nested(bind("name", "biggestcity").and("population", "biggestpop"))        .and("smallestcity")        .nested(bind("name", "smallestcity").and("population",  "smallestpop")),     sort(asc, "state")  ); 

remember output of aggregation bind in zipinfo.class.

the reference link spring mongodb api , documentation.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -