Search code examples
javamongodbspring-bootmulti-tenantjavers

JaVers in multi tenant architecture


I need to integrate my application with Javars. But, my application is multi tenant. I am trying to integrate JaVers mongodb. I succeded in integrating JaVers. But, when the app is started, JaVers storing it's collections jv_snapshots and jv_head_id in the test database. If I delete the test db and again start the application, still the test db is automatically created and the test db would use by the JaVers.

So, How can I tell JaVers to use my own DB in a multi tenant architecture?


Solution

  • If you are not using Javers' Spring Boot starter:

    def mongoRepository = new MongoRepository(MongoClients.create().getDatabase("my_database"))
    javers = javers().registerJaversRepository(mongoRepository).build()
    

    If you are using Javers' Spring Boot starter, Javers will automatically connect to your application's database.

    And there is no notion of tenant in Javers. All you can do is to create one Javers instance per tenant or more generally one Javers instance per one db configuration.