I'm a really n00b playing with NodeJS and MongoDB. I want to build something that could be a really big application. So I try to design the application as much decoupled as I can.
I see it would be nice abstracting the persistence layer for keeping the business logic unaware of how the data is stored (Im not really sure if I will have to switch out MongoDB for a RDBMS in the future). Knowing that, I have thought about creating a FACADE with the needed operations for data-storage, using Mediator patron for subscribing to the FACADE operations and implementing them. This mediator would connect to facade using event-listeners and facade would use event-emitters. Then, the models which subscribe to the mediator will contain all the mongoose Schemas and will be in charge of all the databases/persistence issues. (Does it makes sense?)
I see mongoose is really tight to the data-models. Ie. I see is expected I will not have a Player prototype but a PlayerSchema and a PlayerModel. So:
- Should I use the mongoose data-models? (is there any limitation/problem in doing this? -besides having to rewrite them if i switch-out the DB-)
- Should I transform mongoose data-models into my business-logic prototypes (by this FACADE component)? Should I try another ORM for acceding MongoDB data?
I really want to make these abstractions because I'm very new to JavaScript, Node and all these technologies (so I want to test each part isolated and be able to switch layers if I see there are better solutions).
Any advice will be very welcomed!