title: Agrregation using mongoDBtemplate for Nested document
body: <p>I am trying to use agrregation using spring mongodb template. The grouping has to be done on third level of document. input document is</p>
  
  <pre><code>{
      "_id": "59036b0fa036cc28c8e07db6",
      "sections": [{
          "srcName": "test1",
          "data": [{
                  "srcKey": "",
                  "rowIdx": 0,
                  "values": [{
                          "srcDesc": "Assets"
                      },
                      {
                          "srcDesc": "NonAssets"
                      },
                      {
                          "srcDesc": "liabilities"
                      }
                  ]
              },
              {
                  "srcKey": "01",
                  "rowIdx": 1,
                  "values": [{
                      "srcDesc": "NonAssets"
                  }]
              }
          ]
      }]
  }
  </code></pre>
  
  <p>Essentially I want to run query like</p>
  
  <pre><code>select distinct(srcdesc) from document where srcName="test1"; 
  </code></pre>
  
  <p>Please see that srcDesc is third level of nesting. I am trying below java code</p>
  
  <pre><code>  private MatchOperation getMatchOPeration(String sectionName){
        Criteria criteira=Criteria.where("sectionName").in(sectionName);
        return match(criteira);
    }
  
    private GroupOperation getGroupOperaion(){
        return  group("srcDesc").last("srcDesc").as("srcDesc"); 
    }
  
   private ProjectionOperation  getProjectionOPeration(){
        return project("srcDesc").and("srcDesc").previousOperation();
    }
  
   public List&lt;SourceName&gt; findAllSourceNamesBySection(String sectionName){
         List&lt;SectionsDocument&gt; sourceNameList=new ArrayList&lt;&gt;();
         MatchOperation matchOPeration=getMatchOPeration(sectionName);
         GroupOperation groupOperation=getGroupOperaion();
         ProjectionOperation projectionOperation=getProjectionOPeration();
         AggregationResults&lt;SectionsDocument&gt; aggregationResults=
         mongoTemplate.aggregate(Aggregation.newAggregation(
              matchOPeration,
              unwind("sections.data.values"),
              groupOperation,
              projectionOperation),StatDocument.class,SectionsDocument.class);
              sourceNameList=aggregationResults.getMappedResults();   
         return new ArrayList&lt;&gt;();
    }
  </code></pre>