title: Spring Boot Data Aggregation with MongoDB
body: <pre><code>db.yorum.aggregate([
      { $match: { bayiId: "5848631a2aa9191f78ff3847" }},
      { $group: { _id: "$bayiId" ,avg: { $avg: "$yildiz" }}}
  ])
  </code></pre>
  
  <p>How can i will use in Spring Boot?</p>
  
  <p>i need a "yildiz" avg.</p>
  
  <p><a href="https://i.stack.imgur.com/64Qgx.png" rel="nofollow noreferrer">my collection</a></p>
  
  <p><a href="https://i.stack.imgur.com/1kM5l.png" rel="nofollow noreferrer">avg_yildiz</a></p>
  
  <p><strong>MongoDBConfig.java</strong></p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages="com.application.repository")
  @EnableMongoRepositories(basePackages = "com.application.repository")
  @EnableMongoAuditing(modifyOnCreate=false)
  public class MongoDBConfig extends AbstractMongoConfiguration {
  
      @Override
      protected String getDatabaseName() {
          return "application";
      }
  
      @Override
      public Mongo mongo() throws Exception {
          return new MongoClient("localhost", 27017);
      }
  
      @Bean
      public MongoExceptionTranslator exceptionTranslator() {
          return new MongoExceptionTranslator();
      }
  
      @Bean
      public LoggingEventListener logginEventListener(){
          return new LoggingEventListener();
      }
  
  }
  </code></pre>
  
  <p>MongoDB Configure class. How can i add mongoTemplate ?</p>
  
  <p><strong>Edit</strong></p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Unsupported entity
    com.application.domain.Bayi! Could not determine IsNewStrategy.</p>
  </blockquote>
  
  <p>How can i save repository?</p>
  
  <pre><code>bayiRepository.save(seciliBayi);
  </code></pre>