0

I have 2 instances of Java server running in a docker along with the MongoDB database. We use mongock to migrate the MongoDB data which works fine. I have developed a feature where user can export specific data from the MongoDB from one instance and can import into another instance. The problem arises when the above-mentioned instances are not on the same version,

  1. Source instance version is greater than destination instance: Import-export is not possible as source instance might have enhanced features which destination instance is not yet introduced to
  2. Source instance is lower than destination instance: This imported data should be automatically migrated to the latest version so that destination instance can make sense out of it

I'm looking to address the 2nd case specifically. I tried to look for this kind of specific use case but was unable to find any relevant example.

GeertPt
  • 16,398
  • 2
  • 37
  • 61
hexagon
  • 1
  • 1
  • 2
  • The version you mean MongoDB version or version data with in MongoDB which you are importing ? – Aravind.HU Aug 23 '21 at 07:55
  • The versioned data in mongoDB that I'm importing to the destination instance – hexagon Aug 23 '21 at 09:06
  • What you are doing is something really bad, Ideally you should use Replication in MongoDB – Aravind.HU Aug 23 '21 at 17:08
  • I think it makes sense: you have a version X of your application running on one instance and a version Y of your application on the other, and you use MongoCK to run migration scripts on the data. It works when you upgrade from version X to version Y in-place, but you want to run versions X and Y in parallel, and migrate the data incrementally? That's a more complex problem, I don't think MongoCK supports that. – GeertPt Aug 24 '21 at 09:27
  • @GreyFairer any idea how to achieve this? – hexagon Aug 27 '21 at 04:52
  • The best I came up with, is to create manual upgrade actions in your importer and check while importing which upgrade actions need to be executed per record. – GeertPt Aug 30 '21 at 08:08

1 Answers1

0

I don't fully understand what nor why you are doing that. Can you provide more context? Why do you need to migrate from-to different instances? Why are not having them synchronized(code and data), actually that's the main Mongock's motivation ?

However, if you are really forced to that, which I 'd like to understand, why not disallow backward imports. So the user can only import data from a more updated data source, but not vice versa.

If you can do that, you can fix it by always upgrading your data in such a way that is backward comaptible.

Said that, I really thing the full approach is not right, but I don't have context neither to evaluate the scenario and teh reasons that motivated you to do that.

Mongock team
  • 1,188
  • 5
  • 9
  • Need/Motivation: We have a cloud as well as self-hosted instances running our Java servers. We are a low-code platform where user can build their products using our utility widgets. So more often than not we get request like user have created a app on our cloud instance and now they want to self host but don't want to create a complete app again, in this scenario import-export fits perfectly. But in our release cycle we have staged releases first we release on our cloud to check if their are any breaking changes and if all is well we release to other instances within next 48hrs. – hexagon Aug 24 '21 at 10:31
  • Considering above scenario we want to provide a way for users to import application which is of version lower than the current instance. I was thinking something like selective migration on the JSON payload that we use for migration and save these to the actual collection after the migration is successful or by providing documents to run the migration on – hexagon Aug 24 '21 at 10:38