Hi all,
I have successfully used Axon 3 with a custom event store and a SQL query repository. I now have a requirement to build an API that used MongoDB as the query repository. Event sourcing is a plus as long as it uses MongoDB, but not hard requirement. I immediately thought of using Axon, but I’m not sure if MongoDB can be configured as the query repository as well as the event store. Is this possible and/or has anyone attempted to do this?
Thanks,
Bruno
Hi Bruno,
There is no problem at all to use (the same) MongoDB for your query repositories.
Since you already have a Mongo configuration, you only need to add @EnableMongoRepositories("") to your configuration class.
This will enable you to create repositories for your querymodel (extending MongoRepository)
Example:
public interface OrderEntryRepository extends MongoRepository<OrderEntry, String> {
List<OrderEntry> findByCreatedBefore(Date end);
List<OrderEntry> findByCreatedBetween(Date start, Date end);
List<OrderEntry> findByProductTypeOrderByTypeAscStartAsc(String productType);
}