multi-database access for reading within a changeSet #334
-
In our project we are using mongock for migration, till now in every migration we needed to connect with only one mongo data base but now we have use case where we want to access two mongo database from a single changeset. We went through mongock documentation but could not find any example of using multiple database. Below is the code snippet of how we are currently creating a mongock runner val mongoClient = MongoClients.create("mongodb://dummyuser:dummypassword@localhost:27017/databaseNameA")
MongockStandalone.builder()
.setDriver(MongoSync4Driver.withDefaultLock(mongoClient, migratorConfig.databaseName))
.addChangeLogsScanPackage("org.my.package")
.overrideAnnoatationProcessor(ConditionalOnPropertyAnnotationProcessor())
.buildRunner()
@ChangeSet(order = "01", id = "testId", author = "Team")
fun modifyLeadRequestForABHI(db: MongoDatabase) {
// migration logic here
} What we looking forward. @ChangeSet(order = "01", id = "testId", author = "Team")
fun modifyLeadRequestForABHI(@Name("databaseNameA") db1: MongoDatabase,@Name("databaseNameB") db2: MonogDatabase) {
} Let us know if something like this is possible with mongock. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Hello @ashishkujoy , as part of the version 5, which we are working on, we are providing a multi-tenant feature. Although we haven't finished the design yet, our idea is to make Mongock able to support multiple MongoClients and apply all the changeLogs(or a subset by filtering) to all the mongoClients. However, from your description, that's not exactly what you mean. You are trying to connect to multiples databases in the same changeSet. I am wondering if you really need that or the multi-tenant feature I just described would work for you. If not, could you please provide some more context to understand your scenario and why the need of accessing to two(could be N) databases in the same changeSet? Take into account that a changeLog/changeSet is linked to a single database, it wouldn't make sense to write to multiple databases in the same changeSet. A bit more sense, could be if you have the second databases just to read, but the actual changes are only to one database. As said, please share you scenario and we'll see the best solution 😃 |
Beta Was this translation helpful? Give feedback.
-
Thanks @dieppa for a quick reply. In the change set we want to read a field from a collectionA of database A and add that field in another collectionB of database B. |
Beta Was this translation helpful? Give feedback.
-
Hi @dieppa , In our setup we have one MongoDB instance with a database per customer. Each database has for example an event collection. Can we migrate the event collection in all the databases with one script using the multi-tenant feature? Regards |
Beta Was this translation helpful? Give feedback.
-
Hello @vbotteman , in short, yes, you can do a single mongock migration and apply it to all your client databases by using the multi-tenant feature. We haven't provided documentation for this because it's still in beta, but it we'll do it soon. Are you using Spring boot? |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
Hello @ashishkujoy ,
as part of the version 5, which we are working on, we are providing a multi-tenant feature. Although we haven't finished the design yet, our idea is to make Mongock able to support multiple MongoClients and apply all the changeLogs(or a subset by filtering) to all the mongoClients.
However, from your description, that's not exactly what you mean. You are trying to connect to multiples databases in the same changeSet. I am wondering if you really need that or the multi-tenant feature I just described would work for you.
If not, could you please provide some more context to understand your scenario and why the need of accessing to two(could be N) databases in the same c…