Storing Aggregate in Mongo Repository

Hello guys,

Need some help in understanding the approach if one wants to store the Aggregate in Mongo Repository. I implemented custom GenericMongoRepository by extending AbstractRepository and tried saving the aggregate instance using mongo template. But it does not work as there are inherited fields does allow the instance to be saved into mongo.

Would like to hear if any one has ever tried to store an Aggregate into Mongo Repository.

Regards
Pradyumna

Hi,

I haven’t implemented any MongoRepository, but I can imagine that you would need to do some reflection to set the version field. In the end, this is also what Hibernate would do, when inspecting the JPA annotations.
For the eventSequenceNumbers field, which guarantees that newly registered events are assigned a correct sequence number, you can use the protected “initializeEventStream” method on AbstractAggregateRoot.

Cheers,

Allard