by codemac · 9y ago · 0 comments
Yes, you should design your work first, and figure out what type of data you need to store, and how it should be stored.
Just about any application that uses Oracle cannot be "adapted" to use mongodb. It's an entirely different scope, different persistence model, different features... If we were comparing mysql vs postgres, there would be novel-sized comments about how you can't just switch between them.
mysql : postgres :: bicycle : recumbent bicycle
mongodb : oracle :: tricycle : underwater nuclear submarine
They're just soluctions to entirely different business problem domains. This kind of "if the architecture is clean enough it can run on your microwave" attitude is a disease.
However there are plenty of applications why there is no technical reason why they can't work on both though.
Writing application for Oracle I know that I have ACID and transactions, Writing my data access layer I will take advantage of this. I will also consider locking issues and add some kind of cache like Redis to boost read performance.
Writing for MongoDB I have schemaless data and different consistency guarantees. Because my data objects do not have consistent schema my access layer need to be flexible enough to deal with object of different shape. I would probably use dynamic languages like JS/Ruby.
Database choice will guide design and implementation data access layer. It is non trivial to change this. Even MySQL to PostgreSQL can take a lot effort when you have a lot live data.
You can implement it however you want.
How you will create an adaptor that support transaction for both Mongo and Oracle? Answer: You don't because Mongo do not support transaction.
This is like fridge and bookshelf. Both provide storage but cannot be used interchangeably. What would be adaptor for bookshelf to store meat?