0

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!

Dredok
  • 807
  • 1
  • 9
  • 30
  • You may want to look at https://github.com/flatiron/resourceful and https://github.com/codebrew/resourceful-mongo – Jamund Ferguson Jun 27 '12 at 02:13
  • This resourceful looks great! I will have a look also at the entire framework flatiron. The mongo-engine is very early in development stages -as said by his author- but I will keep an eye on it! – Dredok Jun 27 '12 at 09:37

1 Answers1

0

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.

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471