Axon-mongo framework

Hello guys I use axon 4.7 and spring 3.0.6 need some one can help how I can use mongo as created or updated commands in mucroservices need samples code config becuase I try to do but failed

public class AxonConfig {

private String mongoHost;

private int mongoPort;

private String mongoDatabase;

public MongoClient mongo() {
    var mongoFactory = new MongoFactory();
    mongoFactory.setMongoAddresses(Collections.singletonList(new ServerAddress(mongoHost, mongoPort)));

    return mongoFactory.createMongo();

public MongoTemplate axonMongoTemplate() {
    return DefaultMongoTemplate.builder()
            .mongoDatabase(mongo(), mongoDatabase)

public TokenStore tokenStore(Serializer serializer) {
    return MongoTokenStore.builder()

public EventStorageEngine storageEngine(MongoClient client) {
    return MongoEventStorageEngine.builder()

public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
    return EmbeddedEventStore.builder()
            .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))


Hi King,

Can you explain what didn’t work? I’m not sure if you use Spring Boot with the MongDB starter? If so, you kind of don’t have to configure anything, just setting mongo.event-store.enabled to true in your case.

I need to use mongo DB as Event store (White database) but need to know how I can do bcz I use spring boot 3.0.6 and axon 4.7.0

this is my depedency :


I try many time by failed

It’s easier if you use the axon-mongo-spring-boot-starter dependency, that builds on axon-mongo but adds auto configuration.

Hello I am new for that give me full guide please I understand what you are saying but to is difficult sir. please write as simple ex

The mongo branch of giftcard could be used as example.

Let me use it when I found some misunderstanding I will tell you.
Other question I try to run 3 microservices After running and try to test them but return “OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate 1, expected” one of them has 13 records fields, second 10 records fields. can you help what I do

Hello Guys, is possible to use mongoDB as Event store(Write database) and SQL server (Read database) and axon.axonserver.enable=false??? in spring boot 3.0.6 and axon 4.7.0

Seems like something goes wrong loading the aggregate. Is that with Axon Server as event store? Can you share the code for the aggregate?

Not sure what you want to establish. Can you expand for which parts you want to use a relational database and for which parts a document database. Combining both with Spring Boot can become a bit of a challenge, since if you just have one of them, most is auto configured. When you use both you need more manual configuration.

When I run one of them no error return but when I run all microservices, 2 comes with error OUT_OF_RANGE: [AXONIQ-2000] but one work well

Do you use a distributed commandbus? If you use Axon Server, you have one by default. Otherwise you need to solve it differently.

I want to use both once time Mongo as event store(write database) and sql as read database for Bank account. for 3 microservices no distributor commandBus use

I would advise against that. It’s much better to use SQL for the event store and you can use MongoDB for the projection. Why do you want to use MongoDB for the event store?

There are properties to disable auto config for the token store, which you don’t need in your case. However if you already use JPA (SQL) the auto configuration from the mongo extension won’t work. Since those components are already created based on JPA variants. One way out of this is to configure the event store yourself. The easiest way is to copy past from the GitHub repository, and remove the conditionals.