0

In our current project we use MongoDB. Recently there was a request to switch to Postgres. We don't want to drop MongoDB and just migrate to Postges right away. It would be great to have some sort of a switch in app config to use one or the other. I know that is possible to have both in the same app (you can have Mongo config and JPA config). Usually it is done to store different domain objects (one type stored and retrieved from Mongo and the other one is stored and retrieved relational database). In these types of projects there are two domain models that serve corresponding persistence mechanisms.

Is there a way to have some sort of an abstract data model, two implementation for it and config switch that will either use MongoDB or Postgres?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182

1 Answers1

1

Sounds like you should use an interface and then switch to the desired implementation. Not sure if for example Spring's autowiring is the "config switch" you expect, but it should work along those lines.

Community
  • 1
  • 1
xeraa
  • 10,456
  • 3
  • 33
  • 66