1

How would one create a web application (using Java, C# or JavaScript), which would use NoSQL database as a backend, but with some flexibility to change the backend (for example from couchDB to mongoDB), without rewriting a lot of code.

I assume that it would be best to use some framework, like Spring for Java and Wakanda for JavaScript. If this is the way to go, then please name a few frameworks.

I know that there are great differences between different types of NoSQL databases and I also know that it depends on the problem that one needs to solve. But this is a theoretical question, thus I'd like to get many different options that one could use to solve different problems while having an application with NoSQL "independent" (to some point, for example only between graph based) backend.

Thank you for your answers and time.

Ben
  • 2,435
  • 6
  • 43
  • 57
  • *"please name a few frameworks"* - This isn't the right venue for that. Questions which ask for lists or opinions, polling questions, etc. are not on-topic for Stack Overflow. As for the rest of your question, you don't necessarily have to use a framework. Abstracting a NoSQL database is just like abstracting any data persistence layer. In general you separate your presentation logic, your business logic, and your persistence logic. In this case your persistence logic would use something like Mongo, but you can change it to use Couch instead without changing any of the other logic. – David Aug 14 '12 at 18:59
  • Yes, I know. But still if you have a lot of queries, even if you have separate logic you will still need to rewrite a lot of code. If you use SQL then migration from MySQL to PostgreSQL won't be a big problem, but migration from one NoSQL db to another means rewriting a lot of code. I would just like to know what options do people have to ease up the possible migration. – Ben Aug 14 '12 at 19:03

1 Answers1

0

If you truly want to be database independent you have to abstract away all entities and the database access. The most common way to do that is to implement the repository pattern.

Do note that OR/Ms (and NoSQL clients) typically require you to violate encapsulation (public setters or use List<T> instead of IEnumerable<T> for collection properties).

If that's a sacrifice you're willing to take you can probably use your domain entities as database entities too. (imho fine in a small project, but not in medium/large)

jgauffin
  • 99,844
  • 45
  • 235
  • 372