spring-projects-experimental/spring-fu

How to use multiple mongo databases?

Closed this issue · 2 comments

I have to use two mongo databases.
How can I do?
Last one overwrite the first one.

val app = reactiveWebApplication {
    logging {
        level = LogLevel.DEBUG
    }
    configurationProperties<MongoDbConfigProperty>(prefix = "spring.cms.mongodb").apply {
        enable(cmsDataConfig(this.uri))
    }
    configurationProperties<MongoDbConfigProperty>(prefix = "spring.service.mongodb").apply {
        enable(serviceDataConfig(this.uri))
    }
    enable(webConfig)
}

fun main(args: Array<String>) {
    app.run()
}
fun cmsDataConfig(uri: String) = configuration {
    beans {
        bean<CompanyRepository>()
    }
    reactiveMongodb { this.uri = uri }
}

fun serviceDataConfig(uri: String) = configuration {
    beans {
        bean<UserRepository>()
    }
    reactiveMongodb { this.uri = uri }
}

The overriding is due to how beans are registered during initialization.
One way to make it work is to provide a way for naming beans.
There is another issue to work on this specific topic #359

This will be covered by #359 so I close this issue.