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:
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!
If you're not sure what database you're going to end up with you may want to look at using jugglingdb instead of mongoose. That would provide some of the data layer abstractions you're looking for.