I have a MongoDB structure like this:
record = { 'field': 'value',
'field2': 'value2',
'events' : [ { 'event1': 1 }, { 'event2' : 2 }]
}
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?
When doing using MongoRepository, you never really have a concrete implementation. Spring handles everything based on annotations or the names of the methods themselves
UPDATE
Would the correct way to be to implement a custom method on the repository and then use MongoTemplate to do it manually?
Example:
FooRepository.java
public interface FooRepository extends
CrudRepository<Foo, ObjectId>,
AppointmentWarehouseRepositoryCustom {
}
FooRepositoryCustom.java
public interface AppointmentWarehouseRepositoryCustom {
public void pushMethod();
}
FooRepositoryImpl.java
public class FooRepositoryImpl implements
AppointmentWarehouseRepositoryCustom {
@Autowired
protected MongoTemplate mongoTemplate;
public void pushMethod() {
// Push methods here.
}
}