title: How would I do $push using MongoRepository in Spring Data?
body: <p>I have a MongoDB structure like this: </p>
  
  <pre><code>record = { 'field': 'value', 
             'field2': 'value2',
             'events' : [ { 'event1': 1 }, { 'event2' : 2 }]
           }
  </code></pre>
  
  <p>I am using Spring Data MongoDB package to access this data. There will be mainly writes to the data, so I would like to use the native "$push" functionality to add "events" to the "record", but I can't seem to figure out how to do it with MongoRepository without fetching the entire record and then pushing it and saving it back?</p>
  
  <p>When doing using MongoRepository, you never really have a concrete implementation. Spring handles everything based on annotations or the names of the methods themselves</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Would the correct way to be to implement a custom method on the repository and then use MongoTemplate to do it manually?</p>
  
  <p>Example:</p>
  
  <p><strong>FooRepository.java</strong></p>
  
  <pre><code>public interface FooRepository extends
      CrudRepository&lt;Foo, ObjectId&gt;,
          AppointmentWarehouseRepositoryCustom {
  }
  </code></pre>
  
  <p><strong>FooRepositoryCustom.java</strong></p>
  
  <pre><code>public interface AppointmentWarehouseRepositoryCustom {
      public void pushMethod();
  }
  </code></pre>
  
  <p><strong>FooRepositoryImpl.java</strong></p>
  
  <pre><code>public class FooRepositoryImpl implements
      AppointmentWarehouseRepositoryCustom {
  
      @Autowired
      protected MongoTemplate mongoTemplate;
  
      public void pushMethod() {
          // Push methods here. 
      }
  }
  </code></pre>